Why are empty expressions legal in C/C++?

This is the way C and C++ express NOP.


I'm no language designer, but the answer I'd give is "why not?" From the language design perspective, one wants the rules (i.e. the grammar) to be as simple as possible.

Not to mention that "empty expressions" have uses, i.e.

for (i = 0; i < INSANE_NUMBER; i++);

Will dead-wait (not a good use, but a use nonetheless).

EDIT: As pointed out in a comment to this answer, any compiler worth its salt would probably not busy wait at this loop, and optimize it away. However, if there were something more useful in the for head itself (other than i++), which I've seen done (strangely) with data structure traversal, then I imagine you could still construct a loop with an empty body (by using/abusing the "for" construct).


How else could assert(foo == bar); compile down to nothing when NDEBUG is defined?