Messages in this thread | | | Date | Thu, 1 Apr 1999 00:27:02 +0200 | From | Vojtech Pavlik <> | Subject | Re: [OFFTOPIC] Re: A bit off-topic ... (fwd) |
| |
On Wed, Mar 31, 1999 at 04:57:24PM -0500, J. S. Connell wrote:
> 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.
I think this is a problem with gcc's extended syntax, which allows expressions like
a ? b : c = 0;
which would zero either b or c depending on the value of a. So, Gcc treats the expression
x = (y) ? x = 1 : x = 2;
as trying to assign the value "2", depending on the result of the "x = (y)" expression to either "x" (if y is !0) or to "1" (if y == 0) (and then to "x"), where "1" is of course an invalid lvalue.
So, it's enough to put braces around the second assignment.
x = y ? x = 1 : (x = 2);
However, I still wonder why g++ allows this to compile ...
Vojtech
- 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/
| |