Of course. you're writing a = b = c, where a is x, b is (y)?x=1:x and c is 2.
It's illegal to assign (y)?x=1:x to something - that's an obvious invalid
lvalue to me. So x = 2 but what to do with the rest, who knows.
Try this one -
main() {
int x=0, y=0, z = 0;
x ? y : z = 1;
printf("%d %d %d\n", x, y, z);
}
Compiles fine. Output: 0 0 1.
Now set x=1 and find output: 1 1 0.
Isn't that sick :-) gcc 2.7.2.3.
Based on that, a really good compiler could give your above statement as
x = (x=1) = 2
and then come out with x = 2.
> > But if you change it like this:
> > x = (y) ? (x = 1) : (x = 2);
> > then gcc/egcc don't give you an error. Try the same workaround in your own
> > compiler, or upgrade it.
Well, duh. Brackets bind more tightly than equals last time I checked.
David.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/