Broken compilers? (was Re: Comma Operator)
Blair P. Houghton
bph at buengc.BU.EDU
Sun Jan 15 05:31:39 AEST 1989
In article <922 at quintus.UUCP> nair at quintus () writes:
>What should this print?
>
> int x, y;
> printf("%d %d %d\n", (x = 1, y = 2), x, y);
I've emailed the conforming answer. (I fixed the obvious typo, too).
Now, on to controversy.
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?
I mean, the assignment itself is not an expression per se, but a statement,
and comma operators deal in expressions. But then, the assignment operators
are operators, and in this case hold a place up there with functions in
that they are expressions that can become statements with just the
concatenation of a semicolon. It's in the syntax description.
So, "broken?" "Not Broken?" "Not worth the display phosphorescence
energy?" What?
--Blair
"I'm broke, too, but that's not
in the syntax description..."
More information about the Comp.lang.c
mailing list