in reply to Re^4: if/else syntax
in thread if/else syntax
The compiler understands it fine.
Not true. How can the compiler understand it fine when C doesn't define it
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: if/else syntax
by massa (Hermit) on Jun 26, 2009 at 17:33 UTC | |
|
Re^6: if/else syntax
by gwadej (Chaplain) on Jun 29, 2009 at 13:34 UTC |