Dave Steffen wrote:
Gen Zhang writes:
 > I believe The Book specifically allows an optional semicolon at the end
 > of a function declaration in the global scope. They are illegal in a
 > class. And necessary at the end of a class/struct definition. I have a
 > friend who runs into this problem a lot. :D

 Yeah, this is one question - is it legal?

According to the grammar listed as Appendix A of "The C++ Programming Language, Special Edition", by Stroustrup...

  p. 798

        A translation-unit, often called a source file, is a sequence of declarations:

            translation-unit:
                declaration-seqopt


 So 0 or more declaration-seq makes up a source file.

  p. 803 (bottom of page) lists the production rule for a declaration-seq:

            declaration-seq:
                declaration
                declaration-seq declaration


  p. 804 (top of page) tells us the production rule for a declaration rule. a declaration may be entirely replaced by a block-declaration.

  The next production rule tells us that a block-declaration may be entirely replaced by a simple-declaration.

  The next production rule is:

            simple-declaration:
                decl-specifier-seqopt init-declarator-listopt  ;


  Note that the only thing that isn't optional is the semicolon.

  Presuming the book has no typos, presuming the grammar is a valid representation of the C++ specification, then it would seem that a spurious semicolon at the end of any global declaration is itself a global declaration and is not an error. I find it distasteful, but having the extra semicolon does seem to be valid - if my presumptions are accurate.


  And while GCC's acceptance doesn't mean it's valid C++... attached is the obExample.

Brian