Broken compilers? (was Re: Comma Operator)

Blair P. Houghton bph at buengc.BU.EDU
Tue Jan 17 05:50:45 AEST 1989


>->	printf("%d %d %d\n", (x = 1, y = 2), x, y);
>
>In article <1904 at buengc.BU.EDU> bph at buengc.BU.EDU (Blair P. Houghton) writes:
>-A while back, someone indicated that they knew of a compiler optimizer
>-that would reduce something such as the above (ostensibly through
>-constant-reduction) to
>-
>-printf("%d %d %d\n", (1,2), x, y);
>-
>-or maybe even
>-
>-printf("%d %d %d\n", 2, x, y);
>-
>-So, you compiler-writing C-programmers, is this thing broken or what?

Chris Torek (chris at mimsy.UUCP) commands:
[well, some of us think he found his copy of K&R I next to a burning bush...;-]
>Quite thoroughly, unless both x and y are `dead'.
>
>The side effect(s), if any, of any expression that occurs anywhere
>may not be arbitrarily deleted.

If by "dead" you mean that the compiler has made a thorough search of the
subsequently-traceable code, and the printf argument-heap is LIFO, so that
it knows explicitly that x and y are never again referenced, then I think
I follow you.  Someone else emailed that explanation (one of these days
I'll start remembering the names of the helpful people, sorry).  It seems
that we couldn't whine (nor could we tell without disassembling) if a really
smart compiler reduced those expressions.

Of course, if the side-effect of such a "dead" thing was that your PDP-8's
eleventeenth-bit-light blinked, and that bulb was removed and the electrical
contacts hooked to your Mr. Coffee controller, and your new artificially-
intelligent compiler reduced the expression and unwittingly eliminated the
blink, and you failed the CS 101 exam because of caffeine withdrawal...

That would be injustice, eh?

				--Blair
				  "I can't find 'Mr. Coffee' in the
				   Syntax Summary..."



More information about the Comp.lang.c mailing list