A
Anders Wegge Keller
At work, we got into a talk about weird C constructs. One of my
collegues volunteered this line:
(a>b)?a:b = 42;
According to him, he have found three different compilers with three
different ways of handling this. One did nothing, one always assigned
to b, and the last one did what one should expect, were it legal.
We ended up discussing what the acutal problem here is. The
diffrerent compilers we had at hand gave different diagnostics, so
they giv no clue. We narrowed it down to one of two:
1) a and b are not lvalues in this context.
2) This expression invokes undefined behaviour, since there are no
sequence point between (a>b) and the assignment.
collegues volunteered this line:
(a>b)?a:b = 42;
According to him, he have found three different compilers with three
different ways of handling this. One did nothing, one always assigned
to b, and the last one did what one should expect, were it legal.
We ended up discussing what the acutal problem here is. The
diffrerent compilers we had at hand gave different diagnostics, so
they giv no clue. We narrowed it down to one of two:
1) a and b are not lvalues in this context.
2) This expression invokes undefined behaviour, since there are no
sequence point between (a>b) and the assignment.