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 31,736 of 33,346   
   Ulrich Eckhardt to All   
   Re: question about flexable array   
   13 Dec 11 13:40:08   
   
   b1b30478   
   From: ulrich.eckhardt@dominolaser.com   
      
   Am 12.12.2011 23:49, schrieb gaoqiang:   
   > c99 support flexable array, which means a zero-length array as the   
   > last member of a struct.   
   >   
   > the implementation of g++ also supports it.  Howevery, question is :   
   > in an object, virtual function   
   >   
   > table can reside in any place of the object, how can a flexable array   
   > work properly ?   
      
   Firstly, you can only have flexible arrays of POD types, which also   
   excludes types with virtual functions. Now, the containing type may have   
   virtual functions, in that case the implementation-specific pointer to   
   the vtable is usually located at the beginning of the object's memory   
   space, where it doesn't collide with the flexible array at the back.   
      
   However, there is another problem where flexible arrays could collide:   
   If you derive from a class, your derived class objects typically start   
   with the base class subobject, followed by other members[1].   
      
   Still, Pete's response is right and important, this is not a C++ feature   
   so you can not rely on it working in any specific way. Also, for the   
   same reason, I wouldn't even rely on it working in GCC, which might   
   change in the future.   
      
   Uli   
      
   [1] In the case of multiple inheritance, that would be the the   
   baseclasses in their according order followed by other members, i.e.   
   there you could also have collisions with other base classes.   
      
      
   --   
         [ 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