TITLE: the legality of null statements (Newsgroups: comp.lang.c++.moderated, 7 Jun 99) GLASSBOROW: Francis Glassborow >> namespace A >> { >> }; >> >> It is actually an error to have a semicolon here (a purely technical >> language law point AFAIK) ERDEI: ccg@freemail.c3.hu (Andras Erdei) > My silly question: is it an error? Isn't it just dummy? > > I'm routinely terminating my fns with } ; CLAMAGE: Steve Clamage It is an error at namespace scope, although not all compilers enforce it. Null statements are valid: x = y; ; // null statement while( ++*p = ++*q ) ; // null statement Null declarations are not valid, because there is no syntax production that produces a null declaration. At namespace scope there are no statements, only declarations and definitions. At block scope, a declaration is really a declaration-statement, so a null statement can appear between declarations. int i = 3; ; // error at namespace scope, OK at block scope int j = 4; At class scope, there are no null declarations, but there is a special rule for member functions. A semicolon following an in-class member function definition is optional: class C { int f() { return 0; } // OK int g() { return 1; } ; // also OK int x; ; // error }; The rules are the same in C for the C subset of C++. If you think the rules are inconsistent and peculiar, I would not disagree. :-)