if(a) if(b) c(); else d();
means
if(a) { if(b) c(); else d(); }
or
if(a) { if(b) c(); } else d();
Both are right. Neither is right.
I don't know if that was fixed in recent versions of C.
There's actually no ambiguity in the C syntax for your example.
That's not true either. You contradict yourself in the next sentence. You write code for both people and for compilers to read. Ambiguity for either is still ambiguity.
Anyway, the topic wasn't ambiguity but (the avoidance of) traps. C's if/else definitely has pitfalls.
|