This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Class layout differences across platforms ?


On Wednesday, March 20, 2002, at 05:52  AM, Thomas Kuhn wrote:

> I'm wondering how the layout of c++ classes differs on multiple 
> platforms -
> I'm playing around with dynamic object creation and changing pointers to
> virtual functions at runtine without the object noticing.
>
> I know that the size of elementary data types will be different across
> architecturs but how much differs the vtable layout, the base class
> pointers, the variables and the name mangeling scheme between the 
> supported
> platforms.

One issue you should consider in the layout of c++ classes is the 
platform-specific rules for the alignment of structure/class members.  
This can result in different layouts of the same class on different 
platforms, even when the elementary data types are of the same size.  
For example, consider

class C1 {
   char  f1;
   double  f2;
};

The size and alignment of this class and the offset of f2 within the 
class are likely to vary across platforms as the result of varying 
amounts of padding between f1 and f2 required to provide the appropriate 
alignment of f2.

Fred Forsman
Apple Computer, Inc.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]