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,148 of 33,346   
   Dave Harris to Mathias Gaunard   
   Re: allocate memory 'inside' POD   
   16 Apr 12 07:07:29   
   
   59d7b62f   
   From: brangdon@cix.compulink.co.uk   
      
   loufoque@gmail.com (Mathias Gaunard) wrote (abridged):   
   > In practice, in terms of underlying semantics, static_cast,   
   > const_cast, reinterpret_cast and C-style cast all do the same thing.   
   > The C++ style casts are only useful to make what you're doing more   
   > explicit and protect against pointer casts you don't really mean to   
   > do.   
      
   I don't think that's true, in general. For example:   
        struct Base1 { int x; };   
        struct Base2 { int x; };   
        struct Derived: Base1, Base2 {};   
      
        Derived d;   
        Base2 *p2r = reinterpret_cast(&d);   
        Base2 *p2s = static_cast(&d);   
        assert( p2r != p2s );   
      
   P2r will numerically be the address of d, just with a different type;   
   p2s will be the address of the sub-object within d, effectively offset   
   by sizeof(Base1).   
      
   (I'm sorry if I'm being pedantic, but your statement, even in context,   
   did not seem limited to the current situation.)   
      
   -- Dave Harris, Nottingham, UK.   
      
      
   --   
         [ 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