C's triadic operator.

Karl Heuer karl at haddock.ima.isc.com
Wed May 24 01:46:46 AEST 1989


In article <26388 at watmath.waterloo.edu> rbutterworth at watmath.waterloo.edu (Ray Butterworth) writes:
>[If the operands are brought to the common type (void *), then you silently
>get nonsense from the (incorrect) code]
>    if (!dbuf)  dbuf = sbuf ? sbuf : ( cbuf ? cbuf : malloc(1000) );
>[On the other hand, if the result has the non-voidptr type, then you could
>lose information from the (plausible) code]
>    vp = cond ? dp : vp;

Looks to me as though the "right" answer would have been to insist that the
operands shall have the same type%.  Let the user explicitly specify which one
is meant; this ought to reduce the "surprise factor".

Hopefully, quality implementations will have an option to warn about such
constructs.  I always use an explicit cast on type conversions anyway.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint
% With the usual exception when one operand is a null pointer constant.



More information about the Comp.std.c mailing list