conditional expression evaluation question

John P. Nelson jpn at teddy.UUCP
Wed Jan 14 07:43:44 AEST 1987


>	while (cp < end && triples < MINSKIP)
>		if ((*cp++ | *cp++ | *cp++) == 0) ++triples;
>		else triples = 0;

Assuming that bitwise OR is really what you wanted, this code fragment will
probably break several existing compilers.  As for ANSI C, they introduced
the concept of sequence-points, at which points all side effects must have
taken effect.  Sequence-points occur at && || , :? operators (and the end
of the expression).  There are no sequence points in that bitwise OR
expression.  To quote the standard (under the ++ operator):  "The side
effect of updating the stored value of the operand may be delayed until the
next sequence point is reached."

This says to me that a ANSI conforming C compiler is free to optimize all
the increments to the end of the expression if it wishes to.  The above
code would be unportable.



More information about the Comp.lang.c mailing list