Broken compilers? (was Re: Comma Operator)

Doug Gwyn gwyn at smoke.BRL.MIL
Sun Jan 15 10:07:40 AEST 1989


In article <1904 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) writes:
->	printf("%d %d %d\n", (x = 1, y = 2), x, y);
>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?

The second reduction is of course equivalent to the first.
However, both are broken (assuming x or y is used afterwards),
because after the statement containing printf(), x is required
to contain the value 1 and y must contain the value 2.  Leaving
their contents unchanged is not permitted (unless the program
cannot detect it, e.g. if their values are afterwards unused).

>I mean, the assignment itself is not an expression per se, but a statement,

No, assignments are expressions, not statements.  Sticking a semicolon
after an expression turns it into a statement.



More information about the Comp.lang.c mailing list