Re: [OFFTOPIC] Re: A bit off-topic ... (fwd)

Rivalino Matias Junior (rivalino@unoesc.rct-sc.br)
Thu, 1 Apr 1999 11:30:19 -0400 (AST)


Hi Jeff,
Searching a response to this result, I'm creating the asm code for the line:
x=(y) ? x=3:x=4; /* For y = 1 */

The first result is the value 3 is moved to x. In this point the operator
?: was resolved. Next, the 4 value is moved to x.In this point the operator
= (minor precedence that ?:) was resolved. To produce the asm code I'm using
the Borland C++.

Regards,

RMJ.

> > >I suspect there's a compiler bug to do with assignments in a
> > > ternary operator as the rvalue of an assignment.
> >
> > The expression is correct.
>
> The _expression_ is correct - the _compiler_ is buggy.
>
> > > Wrapping the two x='s on
> > > the right-hand side generates the expected output.
> >
> > No. The expected output is X equal to the result of two other expression
> > (E1,E2), related to condition (y).
> > x= (condition) ? E1 : E2;
>
> 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.
>
> --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/