if ( x && y ) or if ( x ) then if ( y ) ...

News system news at ism780c.isc.com
Wed Sep 19 06:40:41 AEST 1990


In article <1990Sep15.195547.2861 at sea.com> keck at sea.com (John Keck) writes:
>
>K&R, original edition, p. 19: "Expressions connected by && or || are
>evaluated left to right, and it is guaranteed that evaluation will stop
>as soon as the truth or falsehood is known."
>
>Does any one know of a C compiler which does *not* short ciruit these operators?
>

I know of one that did not do short circuit (it does now :-) in the following
case:

   a = -1;  b = 1;
   ++a && ++b;

In this example b had the value 2 after execution of the second line.  The
reason I am aware of the problem is that I had to fix the bug (I did not
write the compiler).  The compiler worked properly when the && appeared
inside an 'if', 'while' or as the second expression in a 'for'.

BTW: the bug was not found by the compiler validation suite.  The compiler
was also used to compile all of the Unix sources without the bug showing
up.  So there might be other compilers with a similar unknown bug.

   Marv Rubinstein



More information about the Comp.lang.c mailing list