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

Arvind Sankar (arvinds@mit.edu)
Wed, 31 Mar 1999 17:20:33 -0500


On Wed, Mar 31, 1999 at 04:57:24PM -0500, J. S. Connell wrote:
>
> 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.

The expression is not valid C. It parses as
x = ((y ? (x = 1) : x) = 2);
Which of course is illegal.

After adding disambiguating parentheses, the expression is syntactically correct,
but its effect is undefined: you cannot change the variable being assigned to in
the expression on the right side of the assignment.

Think i = i++;

btw, this would really be more suited to comp.lang.c

-- arvind

-
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/