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 32,279 of 33,346    |
|    Alf P. Steinbach to William Lee    |
|    Re: Constructor-like initialization of p    |
|    10 May 12 21:20:30    |
   
   883f14a1   
   From: alf.p.steinbach+usenet@gmail.com   
      
   On 10.05.2012 23:26, William Lee wrote:   
   >   
   > In C++ some primitives can be initialized using constructor-like   
   > syntax, like   
   >   
   > int x = int(); // will zero-initialize x   
   >   
   > However, for primitives with multi-word types, I see different   
   > behavior depending on the compiler. For example:   
   >   
   > long long ll = long long();   
   > unsigned int ui = unsigned int();   
   >   
   > In 2 compilers I tried (clang 3.0 and GCC 4.7), the above two lines   
   > of code fail to compile because of the free-standing "long" and   
   > "unsigned" words, respectively. A third compiler (MSVC) compiles the   
   > code successfully.   
      
   MSVC is formally wrong but most practical, I think.   
      
      
   > I know the alternatives (like using "0" as an initialization value),   
   > but I'm curious to know what is the expected behavior for using   
   > constructor- like syntax for initialization of these primitives.   
      
   "long long" is not a proper typename. E.g. you can't do "x.~int()",   
   and likewise you can't do "x.~long long()". But with just a little   
   typedef you can do "x.~Int()" and "x.~LongLong()", with proper names.   
      
   Instead of explicit naming, with old C++03 you can always do   
      
    template< class TypeT >   
    struct Type { typedef TypeT T; };   
      
   and write   
      
    long long ll = Type
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca