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
These semicolons are useless as others have pointed out already. The only thing I want to add is that IMO, these are optimized out anyway i.e., compiler doesn't generate any real code for these.
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.
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.
that's dummy statememt. You sample is identical to
if (x == NULL) {
// some code
do_something_here();
}
/* empty (dummy statement) here */ ;
// more code
some_other_code_here();
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:
if(condition for tbd block)
;
else {
//Some code here
}
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.