Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cmcl2!yale!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!ncar!ico!ism780c!news From: news@ism780c.isc.com (News system) Newsgroups: comp.lang.c Subject: Re: if ( x && y ) or if ( x ) then if ( y ) ... Message-ID: <47590@ism780c.isc.com> Date: 18 Sep 90 20:40:41 GMT References: <5781@uwm.edu> <1990Aug17.164730.25750@zip.eecs.umich.edu> <367@bally.Bally.COM> <1990Sep15.195547.2861@sea.com> Reply-To: marv@ism780.UUCP (Marvin Rubenstein) Distribution: usa Organization: Interactive Systems Corp., Santa Monica CA Lines: 25 In article <1990Sep15.195547.2861@sea.com> keck@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