Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C++ class member alignment in Xcode



Hello,

I am having a problem with a derived class accessing members in the base
class.  It looks like this:

In file CClassA.cpp
class classA
{
public:
	short mem1;
	long	mem2;
	Boolean	mem3;
	Boolean	mem4;
	Boolean	mem5;
	Boolean	mem6;
	Boolean	mem7;
	Handle	mem8;
};

In file CClassB.cpp
class classB : public classA
{
	UInt32	mem9;
};
 
If I reference mem8 from classA everything works fine.  When I try to
use the handle mem8 from classB I crash.  Upon investigation classB has
a different offset for mem8 then classA has.  ClassA is aligning members
on a 4-byte boundary while classB is aligning on a 2-byte boundary.  I
can not find any file level properties for member alignment.  

I have preformed a clean rebuild of the project and get the same result.
Why does one file use 4-byte alignment while another on in the same
project uses 2-byte?

Regards,

Ron Lingl
Interactive Solutions, Inc.


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.