> 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);
> }
>
> gcc version: 2.7.2.3
> egcc version: 2.91.61 19990216
> g++ version: 2.91.61 19990216
>
> 20145 16:50:24 jsc@squeak:~% gcc -g -o test test.c
> test.c: In function `main':
> test.c:7: invalid lvalue in assignment
> 20146 16:50:28 jsc@squeak:~% egcc -g -o test test.c
> test.c: In function `main':
> test.c:7: invalid lvalue in assignment
> 20147 16:50:34 jsc@squeak:~% g++ -g -o test test.cc
> 20148 16:50:43 jsc@squeak:~% ./test
> 1
>
> 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.
>
[SNIPPED]
> > The expression is correct.
>
> The _expression_ is correct - the _compiler_ is buggy.
>
The expression is not correct. "The result of an operation that
modifies a variable two or more times without an intervening
sequence-point is undefined..."
FYI, the only sequence point is ';'. This is just like the
x = x++; trick. x is undefined.
Cheers,
Dick Johnson
***** FILE SYSTEM WAS MODIFIED *****
Penguin : Linux version 2.2.5 on an i686 machine (400.59 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.
-
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/