🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac.programmer.codewarrior
Article #826

Re: Alignment (padding) of derived classes, Mach-O vs. CFM

#826
From: Stefan Haller
Date: Fri, 20 Jun 2003 12:39
49 lines
3040 bytes
Ed Swartz <eswartz@antispam.metrowerks.com> wrote:

> Well, even given the specific rules, your problem is deeper than the member
> layout.  CFM and Mach-O use completely different ABIs, so the layout of C++
> objects is unlikely to correspond between the two (the vtable pointer, for
> instance, is in different places).  CFM is based off a 16-bit 68K
> architecture, while Mach-O is based off a 32-bit PPC architecture, so there
> are inherent unconfigurable differences in the ways the invisible parts of
> the classes are aligned.

Our classes do have virtual functions (destructors, mostly), but we are
careful to call them only from the Mach-O side.  This is working fine.

We are not using any other RTTI features on these objects.

So far it seems that the alignment problem with derived classes is the
only problem in practice.  We had this only for very few classes, and
were able to fix the problems by manually padding the classes.  The
problem with this approach is that it is hard to test.  (We are
considering putting

  BOOST_STATIC_ASSERT((sizeof(MyClass) % 8) == 0);

after the declaration of each of the shared classes, but this is still
easy to forget for new classes.)

> I would recommend using C structs instead.

This is not an option.  We have a very large code base that is already
using these C++ classes, there's no way we can rewrite it all, using
different data structures.

> Beyond that, #pragma pack(1) ... pack(8) would be best for assuring the
> struct layouts are the same between the two compilers.

The C compiler manual doesn't list this as supported by the Mac
compilers.  #pragma pack(1) does work though, and it even achieves the
desired effect of getting the same alignment on both Mach-O and CFM;
however, it is completely useless, because it will merrily put ints and
doubles on odd addresses.

To sum it up: it seems that manually padding our classes to multiples of
8 bytes is our only option, right?


-- 
Stefan Haller
Berlin, Germany
http://home.snafu.de/stk/
Technical Details
Message-ID: <1fwuuqx.ngui9t15gtnejN%stk@snafu.de>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!eusc.inter.net!news.eusc.inter.net!stk
References: <1fwrc5z.1wbucc58vha4aN%stk@snafu.de> <bctluk$kn0$1@newshost.mot.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10bcce,98e56c06675247cc
X-Google-Attributes: gid10bcce,public
X-Google-Thread: f635e,98e56c06675247cc
X-Google-Attributes: gidf635e,public
X-Google-ArrivalTime: 2003-06-20 05:39:35 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!eusc.inter.net!news.eusc.inter.net!stk
From: stk@snafu.de (Stefan Haller)
Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac
Subject: Re: Alignment (padding) of derived classes, Mach-O vs. CFM
Date: Fri, 20 Jun 2003 14:39:15 +0200
Organization: none
Lines: 49
Message-ID: <1fwuuqx.ngui9t15gtnejN%stk@snafu.de>
References: <1fwrc5z.1wbucc58vha4aN%stk@snafu.de> <bctluk$kn0$1@newshost.mot.com>
X-Trace: news.eusc.inter.net 1056112775 17359 213.23.135.207 (20 Jun 2003 12:39:35 GMT)
X-Complaints-To: abuse@eusc.inter.net
Mail-Copies-To: never
User-Agent: MacSOUP/2.5b2 (Mac OS X version 10.2.6)