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 32,276 of 33,346   
   Johannes Schaub to All   
   Re: Constructor-like initialization of p   
   10 May 12 16:19:29   
   
   883f14a1   
   From: schaub.johannes@googlemail.com   
      
   Am 10.05.2012 23:26, schrieb William Lee:   
   { quoted mod comment snipped -mod }   
   >   
   > 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();   
   >   
      
   This doesn't work because a the "type()" thing is only allowed when   
   "type" has the form of a "simple-type-specifier", wich is basically "one   
   name" / "one keyword" specifying a type. It's a syntax error. The   
   compiler that accepts it without a warning is nonconforming.   
      
   You can work it around by using some kind of "identity" template as in   
      
       template   
       using Identity = T;   
      
       long long ll = Identity();   
      
   Alternatively using the "bord tools" of C++11   
      
       long long ll = std::common_type::type();   
      
   Finally in C++11 you can use "{}", which will also result in value   
   initialization like the above cases do   
      
       long long ll{}; // will be zero-initialized   
      
      
   --   
         [ 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