Re: Side effects in conditional expressions

On 2010-10-02 00:08, Chïna Blüe Öyster Cult wrote:
In article<i85kc7$mcj$1@xxxxxxxxxxxxxxxxx>,
August Karlstrom<fusionfile@xxxxxxxxx> wrote:

(x == 0)? x++: y *= 2;

Would this be considered bad coding style? Motivate your answer.

Can you guarentee what will be assigned to what if x==0 or x==1? If not, you
have been answered.

Also x++ is a rvalue, not an lvalue, so even if ?: has been extended to lvalues,
this won't work.

OK, I apparently need parentheses around `y *= 2' so it should read

(x == 0)? x++: (y *= 2);


The competent programmer is fully aware of the limited size of his own skull. He therefore approaches his task with full humility, and avoids clever tricks like the plague. --Edsger Dijkstra