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,145 of 33,346   
   Dave Abrahams to All   
   Re: allocate memory 'inside' POD   
   15 Apr 12 18:21:23   
   
   From: dave@boostpro.com   
      
   on Wed Apr 11 2012, Dave Abrahams  wrote:   
      
   > on Wed Apr 11 2012, Mathias Gaunard  wrote:   
   >   
   >> On Apr 9, 2:50 pm, Dave Abrahams  wrote:   
   >>> on Mon Apr 09 2012, Mathias Gaunard  wrote:   
   >>> > That's not allowed.   
   >>>   
   >>> Why not, if you please?  It has the right alignment and is otherwise raw   
   >>> memory.   
   >>   
   >> Because of strict aliasing rules. In practice it will work since in   
   >> most compilers unions are considered aliasable by all pointer types,   
   >> but that's not the case according to the language.   
   >>   
   >> The only types you can use to alias the content of x are void*, char*,   
   >> int* and boost::aligned_storage<...>::type*.   
   >   
   > Right, but I'm not aliasing the content of x.  I'm aliasing the memory   
   > that follows x.   
      
   I should add a small correction.  There's no aliasing at all (other than   
   char*/double*, which is legal and has defined behavior).  Maybe you would   
   feel better about   
      
       static_cast(   
          static_cast(   
             static_cast(static_cast(&x)) + sizeof(x)))   
      
   but AFAICT that offers no advantages over   
      
       static_cast(static_cast(&x+1))   
      
   --   
   Dave Abrahams   
   BoostPro Computing   
   http://www.boostpro.com   
      
      
         [ 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