lkml.org 
[lkml]   [1999]   [Mar]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [OFFTOPIC] Re: A bit off-topic ... (fwd)
Date
From
> > I understand how ?: works.  What I said was that gcc/egcc would not compile
> > this line:
> > x = (y) ? x = 1 : x = 2;

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/

\
 
 \ /
  Last update: 2005-03-22 13:51    [W:0.056 / U:1.560 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site