Grammar of a C++ Translation Unit -


my understanding, long time now, a c++ translation unit, after preprocessor has run, is sequence of declarations (let me remind definition declaration).

many people have argued statement no 1 has ever given counterexample. myself found example troubles me:

int x;       //declaration  ;            // ??? empty declaration?  int main()   //dec {            //la }            //ration 

this compiles fine msvc , online comeau. know standard defines empty statement never heard of empty declaration. so, see 3 options:

  • my understanding correct , standard defines empty declaration
  • my understanding correct standard doesn't define empty declarations , above translation ill-formed
  • my understanding incorrect, i.e. c++ tu not sequence of declarations

please me dissolve doubts.

an empty-declaration allowed in (the current draft of) c++0x @ file scope (and namespace scope , other places declaration allowed) , semicolon. standalone grammatical entity.

in c++03 lone semicolon not allowed declaration expected. although might appear simple-declaration might able reduce semicolon explicit rule disallows this.

7 [dcl.dcl] / 3

in simple-declaration, optional init-declarator-list can omitted when declaring class (clause 9) or enumeration (7.2), is, when decl-specifier-seq contains either class-specifier, elaborated-type-specifier class-key (9.1), or enum-specifier.

in short implies init-declarator-list can omitted when decl-specifier-seq not omitted.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -