Language design or compiler bug with semicolons?

I have a well above basic knowledge about C++ (variables, arrays, functions, classes, virtual functions, polymorfism, templates etc.), but there is one thing that has paid my attention:

1
2
3
4
5
6
7
#include <iostream>
using namespace std;

int main(){
	system("PAUSE");
	return 0;;;;
}


I discovered this by total accident. It has bothered me, because to my knowledge, this probably shouldn´t be legal C++ code albeit compilers, both DevC++ and Visual Studio, accept it without any warnings or errors. Any ideas about this thing´s correctness?
Last edited on
That's legal.
What you have is
the return 0; statement followed by 3 empty statements.

Be careful not to fall into the common trap of believing that the tool made a mistake. People make mistakes. While tools also fail, it is usually the result of misuse or abuse. When there is a genuine error in a tool, people more experienced than you or I and much more familiar with the tool than you or I will already know about it and be working on fixing it, and in the meantime will have the problem listed for the users of the tool.
Thanks for the replies. I agree with Duoas, I´d better believe I´ve made a mistake myself, but because this one seemed so weird, I had to ask further information about it. But why that kind of thing has actually been left into C++? Does somebody really want to code like that?

Well, anyway, I think I have found answers good enough, but of course I´d like to see more feedback and other opinions, too. Thanks again so far.
Henrick wrote:
Does somebody really want to code like that?

Of course.

1
2
3
4
for(;;)
{
  //loop code
}
Well I prefer

1
2
3
while(1) {
 //loop code 
} 
Oops, I forgot that for loop thing, although it isn´t one the best possible solutions to nearly any problem...
What if you want a for loop with a variable you already initialized?
for(; var < var2; ++var)
Sheesh, you´re right, I forgot that. I seem to keep forgetting things, although I have used that more than once. That´s definitely useful of course. Good point.
Last edited on
Topic archived. No new replies allowed.