Messages in this thread | | | Date | Thu, 1 Apr 1999 03:51:14 -0500 (EST) | From | Alexander Viro <> | Subject | Re: [OFFTOPIC] Re: A bit off-topic ... (fwd) |
| |
On Wed, 31 Mar 1999, J. S. Connell wrote:
> On Wed, 31 Mar 1999, Rivalino Matias Junior wrote: > > > Okay. Try in C++ compiler (e.g. g++). I'm using g++ in this case. > > #include <stdio.h> > > void main() { > int x = 0; > int y = 1; > > x = (y) ? x = 1 : x = 2;
Which is
x = ( (y) ? x = 1 : x ) = 2
> I believe that gcc/egcc are buggy here - your code _should_ be legal. > Also, whatever version of g++ you are using is _also_ buggy - it should be > generating code to produce 1, not 2, but it is not.
Really? See above. ?: has *higher* priority than =. Depending on whether the result of = is considered as l- or r-value it is either correct and equivalent to
x = ( (y) ? (x = 1) , x : x ) = 2
i.e. if (y) x=1; x = x = 2;
or invalid (for r-value variant).
> I understand how ?: works. What I said was that gcc/egcc would not compile > this line: > x = (y) ? x = 1 : 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.
It's about the same "workaround" as for "WTF 1+1*1+1 is not 4 ???"
- 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/
| |