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 33,061 of 33,346   
   Bart van Ingen Schenau to Stuart   
   Re: [Solved] sequence of inheritance fro   
   19 May 13 06:57:33   
   
   From: bart@ingen.ddns.info.invalid   
      
   On Sun, 19 May 2013 01:04:51 -0600, Stuart wrote:   
      
   > Well, I learned something too. I didn't know that the compiler is   
   > allowed to lay out the base class members in a different order than   
   > the one that is given in the class definition. So if one has to   
   > achieve some memory layout, one has to take special care if one of   
   > the base classes contains virtual methods.   
      
   Actually, even without virtual functions you can not count on any   
   order of the base-class sub objects. The standard explicitly has made   
   that order unspecified.   
      
   And it gets worse (although slightly less so with C++11).  If you have   
   this structure:   
      
      struct X {   
        public: int i;   
        private: char c;   
        public: float f;   
      };   
      
   then a C++98/C++03 compiler is free to rearrange all three members in   
   any order it likes (members may be reordered if there is an   
   intervening access specifier).   
   A C++11 compiler must keep i and f in the current order, but it can   
   move c about at will (members with different access levels may be   
   reordered relative to each other. members with the same access level   
   must keep their declared order).   
      
   Your best bet to create a structure with a defined layout is to   
   declare it as a C-compatible structure (no base classes, no access   
   specifiers, no virtual members).   
      
   { Quoted signature removed -mod }   
      
   Bart v Ingen Schenau   
      
      
   --   
         [ 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