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,241 of 33,346   
   Alf P. Steinbach to cartec69@gmail.com   
   Re: Most-derived objects objects shall h   
   04 May 12 17:36:41   
   
   eeda2344   
   From: alf.p.steinbach+usenet@gmail.com   
      
   On 05.05.2012 00:15, cartec69@gmail.com wrote:   
   > On Thursday, May 3, 2012 4:25:04 PM UTC-5, Johannes Schaub (litb) wrote:   
   >> The C++11 spec says at 1.8p5   
   >>   
   >> "Unless it is a bit-field (9.6), a most derived object shall have a   
   >> non-zero size and shall occupy one or more bytes of storage. Base class   
   >> subobjects may have zero size."   
   >>   
   >> The following is supposed to be valid   
   >>   
   >>     int *x = new int[0];   
   >>   
   >> The object created by "new int[0]" has zero size (int[0] == 0 *   
   >> sizeof(int)), but that contradicts the above quote.   
   >>   
   >> How is this to be interpreted?   
   >   
   > There is no contradiction if sizeof(*new int[0]) != 0, which is true   
   > at least for GCC 4.6.3. 5.3.3/2 (sizeof) says that "When applied to   
   > an array, the the result is the total number of bytes in the array. This   
   > implies that the size of an array of n elements is n times the size of an   
   > element". It's not clear to me if "This implies" is meant to define a hard   
   > requirement, but in any case if the intention of the standard is that   
   > arrays of zero elements have non-zero size it would be nice to say so   
   > explicitly.   
      
   That does not apply sizeof to an array type object.   
      
   Cheers & hth.,   
      
   - Alf   
      
      
      
   --   
         [ 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