should statements having no effect be allowed?

is there a good argument for allowing them? if not, should they generate a syntax or parse error? (note: some function calls might have no effect but since it may be impossible to determine whether they do or not, they should probably be excluded from this category.)

examples of what I'm talking about are:

Code:

j;
;;;;;
for(;;);{}

the last example also illustrates how a typo can cause bugs that are difficult to find.

thanks for the input, guys. I'm working on a compiler in my spare time (a superset of C++) and I was considering omitting no-ops from the language. do you think it's warranted - or should I just leave well enough alone? any input would be appreciated.

it just seems to me that they serve no useful purpose, and that we'd be better off if they hadn't been incorporated into the language in the first place. I think I'll allow them, though - if only for the sake of portability. thanks again for the input, everyone.

Apart from examples above where empty statements are useful (even though their need may be debatable), empty statements occur a lot in automatically generated code. They have no effect, and it is difficult in some programs (eg code generators that parse something else to generate code) to eliminate them.

I'd suggest not eliminating them altogether. Having a warning about their presence (preferably a warning that can be turned off, if desired) would be useful for picking up coding errors in hand-written code.

As far as I can tell it should work. continue skips over the rest of the loop body, but not over the post-iteration expression.

Originally Posted by Bjarne Stroustrup (2000-10-14)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.