EDIT: Interesting follow up. I'm using gcc 4.4.5 on Fedora 13.
Code:
#include <stdio.h>
int main(void)
{
int x = 17;
x ? 42 : x++;
x ? 42 : x += 1;
x ? 42 : x = x + 1;
return 0;
}
The first version, with x++, passes the compiler, but the last two give the "lvalue required" error. Is there something fundamentally different that I'm not aware of between those 3 statements? Semantically, they're all the same (they increment x by 1 if x is zero). Furthermore, all 3 of the following work:
Code:
#include <stdio.h>
int main(void)
{
int x = 17;
x ? x++ : 42;
x ? x += 1 : 42;
x ? x = x + 1 : 42;
return 0;
}
I'm not saying any of that is good code, but the inconsistency bothers me.