home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 31,485 of 33,346   
   =?windows-1252?Q?Daniel_Kr=FCgler?= to All   
   Re: When was the default type of int no    
   23 Sep 11 17:19:28   
   
   2408c18d   
   From: daniel.kruegler@googlemail.com   
      
   Am 23.09.2011 21:08, schrieb Agents Marlow:   
   > I am glad that C++ does not assume of type of int if no type is given.   
   > ISTR that in ages past it was allowed but some compilers gave warnings   
   > and now it gives an error.   
   >   
   > I have been doing some C++ tests and came across a question where I   
   > reckon the so-called answer is out of date. You are supposed to say   
   > what is wrong with the code. Here is the code:   
   >   
   > enum TestStatus { not_run = -1, fail, pass };   
   >   
   > int main()   
   > {   
   >    const testsize = 100;   
   >    TestStatus testSuite[testsize];   
   >    return 0;   
   > }   
   >   
   > I said that testsize does not have a type. BrainBench said I was wrong   
   > and that there is nothing wrong with the code.   
      
   If this is really what BrainBench said, then BrainBench is wrong - the   
   code ill-formed and was never valid standard C++ (Let me add that even C   
   has no longer the "implicit int" rule, it has been removed from the   
   second edition of C99 on).   
      
   > But here's what GCC   
   > says:   
   >   
   > a5.cpp: In function 'int main()':   
   > a5.cpp:6: error: ISO C++ forbids declaration of 'testsize' with no   
   > type   
      
   This is to be expected for a conforming compiler.   
      
   > So it looks like BrainBench is out of date. The question is "when did   
   > the std change?". IIRC the default type of int was the case for the   
   > September 1998 std, but there were some amendments afterwards.   
      
   I have the official ISO/IEC 14882, first edition 1998-09-01 (aka ISO/IEC   
   14882:1998(E)) here at my place and this document clearly has no   
   "implicit int" rule anymore, see e.g. C.1.5 Clause p4:   
      
   "Change: Banning implicit int In C++ a declspecifierseq   
   must contain a typespecifier. [..]"   
      
   We also have clause 7 p7:   
      
   "Only in function declarations for constructors, destructors, and type   
   conversions can the declspecifierseq be omitted.78"   
      
   where footnote 78 says:   
      
   "The “implicit int” rule of C is no longer supported."   
      
   or more relevant 7.1.5 p2:   
      
   "At least one typespecifier that is not a cvqualifier is required in a   
   declaration unless it declares a constructor, destructor or conversion   
   function.80)"   
      
   with footnote 80:   
      
   "There is no special provision for a declspecifierseq that lacks a   
   typespecifier or that has a typespecifier that only specifies   
   cvqualifiers. The “implicit int” rule of C is no longer supported."   
      
   > I am   
   > not sure exactly what they were or when they were. I do not include   
   > the very recent C++0x since this is far too recent for BrainBench and   
   > several compilers.   
   >   
   > I am also interested in where in the std it said that the default type   
   > of int would apply (in the example above) and the place in the std   
   > where it now says the default type of int will not be assumed.   
      
   I would say that above quoted 7.1.5 p2 is very clear here. In C++11 this   
   is the identical text in 7.1.6 p3:   
      
   "At least one type-specifier that is not a cv-qualifier is required in a   
   declaration unless it declares a constructor, destructor or conversion   
   function.92"   
      
   with footnote 92:   
      
   "There is no special provision for a decl-specifier-seq that lacks a   
   type-specifier or that has a type-specifier that only specifies   
   cv-qualifiers. The “implicit int” rule of C is no longer supported."   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca