I just ran into some code that overuse semicolons, or use semicolon for different purposes that I am not aware of.
I found semicolons at the end of if-statements and at the end of functions. For instance:
int main (int argc, char * argv[]) {
// some code
if (x == NULL) {
// some code
}; <-----
// more code
return 0;
}; <---
It is compiling with cc, not gcc. What do those semicolons do? I'm assuming that there is no difference because the compiler would just consider it as empty statement.
You are right, the compiler considers them empty statements. They are not needed, I guess the programmer somehow thought they were.
I think that the author may have been going for something like:
which you might do if you were scaffolding code and still wanted it to compile. There's a good chance that it's just an error as Jon suggests though.
The first semicolon (after the if-statement) is just an empty expression which does nothing. I fail to see any point of having it there.
The second semicolon (after the function) is an error since it is outside of any block of code. The compiler should give a warning.
that's dummy statememt. You sample is identical to
They do nothing. They're a sign of someone who doesn't understand the language terribly well, I suspect.
If this is source code you notionally "own", I would remove the code and try to have a gentle chat with the person who wrote it.
These semicolons are not needed (as you said, they are empty statements). Your code compiles with gcc, providing that 'x' is defined (check http://www.codepad.org). There's no reason why a C compiler would refuse to compile your code.