2826c952   
   From: alf.p.steinbach+usenet@gmail.com   
      
   On 04.05.2012 22:06, Chris Uzdavinis wrote:   
   > On May 3, 6:30 pm, "Alf P. Steinbach" +use...@gmail.com> wrote:   
   >   
   >>> 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?   
   >>   
   >> The returned pointer is not a pointer to an object.   
   >>   
   >> It is just a unique pointer value.   
   >   
   > I don't think that is a valid summary. Allocating an array of size   
   > zero returns a pointer to a memory object representing an array with   
   > zero elements.   
      
   No, it can't be an "object" in the standard's sense of "object". As Johannes   
   noted in the original posting, such an object would have zero size, which by   
   §1.8/5 is forbidden for a most derived object, unless that object is a bit   
   field.   
      
   So, your POV is not a valid way to look at it.   
      
   All that we know about the result is that by §5.3.4/7, which I quoted earlier,   
   it is a (dynamically) unique pointer value. It is IMHO needless complication   
   to add more interpretation that is neither specified nor strongly implied by   
   the standard, at    
   least when that interpretation does not confer great explanatory power, and   
   Mr. Occam, with his sharpish razor blade in plain sight, therefore says "no,   
   don't do that, no No NO!". E.g., you don't need to assert a non-zero sized   
   region of memory, because    
   the uniqueness requires a non-zero size region of memory reserved for that   
   pointer, which implies that...   
      
      
   > It will leak if not deleted.   
      
   Yep.   
      
      
   > Dereferencing it has   
   > undefined behavior--just like going out of bounds on any other sized   
   > array. It really uses space in memory so that it has an actual unique   
   > address. If you iterated this array, your begin/end iterators would   
   > both be referring to the same location, designating an empty   
   > range.   
      
   Yes.   
      
   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)   
|