Odd trivia question involving && and ,

Brian Westley Merlyn LeRoy merlyn at digibd
Sat May 5 02:29:13 AEST 1990


aj-mberg at dasys1.uucp (Micha Berger) writes:
>Do these pieces of source code produce significantly different object
>code?

1-
>	E1 &&
>		E2,
>		E3;

2-
>	if (E1) {
>		E2;
>		E3;
>	}

I found that many compilers screw up expression (1);
E2 would often be evaluated even when E1 is false.
They SHOULD produce the same results, but look out
when you operate in the real world.
A/UX (Apple's Unix) even screwed up E1 && E2 as a standalone
statement (it only short-circuited the && in if(), etc, statements).

I found this out as part of my obfuscated C code entry for last year.
----
Merlyn LeRoy



More information about the Comp.lang.c mailing list