Messages in this thread | | | Subject | Re: [OFFTOPIC] Re: A bit off-topic ... (fwd) | Date | Wed, 31 Mar 1999 17:45:08 -0500 | From | Buddha Buck <> |
| |
> 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; > printf("%d\n", x); > } > > 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.
Um... Is it correct? I thought there was some rule about multiple assignments to the same lvalue between sequence points.
I believe there is a sequence point after the evaluation of the lhs of the ?: operator, but I don't know about after the evaluation of the rhs.
The expression may be undefined.
I can't think of any reasonable interpretation that would yield 2, however...
(Is : alone an operator? Somewhere I remember it being a bitfield or strange scoping operator. In that case, it may be interpreting it as
x = ((y) ? (x = ((1:x) = 2)));
which I could see interpreted as 2, in some bizzare sense.)
> 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.
This makes it sound like some evaluation order misunderstanding.
> > --Jeff > > > - > 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/
-- Buddha Buck bmbuck@acsu.buffalo.edu "Just as the strength of the Internet is chaos, so the strength of our liberty depends upon the chaos and cacaphony of the unfettered speech the First Amendment protects." -- A.L.A. v. U.S. Dept. of Justice
- 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/
| |