Article View: comp.sys.mac.programmer.codewarrior
Article #802Re: Alignment (padding) of derived classes, Mach-O vs. CFM
From: Thorrsten Froehlich
Date: Tue, 24 Jun 2003 19:43
Date: Tue, 24 Jun 2003 19:43
40 lines
3181 bytes
3181 bytes
stk@snafu.de (Stefan Haller) wrote in message news:<1fwyaln.v7pwbouxanswN%stk@snafu.de>...
> Thorrsten Froehlich <froetho@charlie.iit.edu> wrote:
>
> > There are more options for alignment, and they are
> > not documented in the compiler manual yet, it seems:
> > You find them in "CW Mac PPC Notes 3.0.txt" in the Release Notes
> > folder. If you play with them a bit, in particular the "power_gcc"
> > options, I guess you get what you want
>
> No. I tried them all before posting; none of them appears to have any
> influence on what happens between a base class and a derived class.
Hmm, so Metrowerks offers control only over C alignment, but no
control whatsoever over C++ structure alignment. I am surprised
regular structs are treated different from classes to such an extend.
If it isn't a bug (I would file it) that the alignment options don't
change behavior of anything C++ ABI related, I would say it is really
a worthwhile feature to be able to exchange data this way. Of course,
if I think about it, I suppose having different alignment might
require some of the compiler-generated code for C++ to be adjusted,
which is more difficult to do than it sounds.
In any case, given that you know where to look for the ABI
specifications, it is possible to work around this problem reliably
using either manual padding as you suggested, or maybe something else:
Did you try putting the members of each class into a separate struct?
That is, will the alignment then match on Mach-O and CFM? I would
assume structs always get aligned, but I don't know if they are...
Alternatively, you could of course recreate the class structure with
structs on either Mach-O or CFM (should be possible with the ABI
specs). With a few scripts one could probably even automate this. That
way, you could adapt to whatever alignment the other side uses. If
performance isn't a major issue, transforming the class structure at
runtime would be another option.
In the end it all depends on how important the ability to make
cross-ABI calls is for you.
Thorsten Froehlich
Technical Details
Message-ID:
<a1ed16f9.0306241143.5112e6cb@posting.google.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mailReferences:
<1fwrc5z.1wbucc58vha4aN%stk@snafu.de> <a1ed16f9.0306201135.5802e437@posting.google.com> <1fwyaln.v7pwbouxanswN%stk@snafu.de>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-24 12:43:30 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail From: froetho@charlie.iit.edu (Thorrsten Froehlich) Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac Subject: Re: Alignment (padding) of derived classes, Mach-O vs. CFM Date: 24 Jun 2003 12:43:29 -0700 Organization: http://groups.google.com/ Lines: 40 Message-ID: <a1ed16f9.0306241143.5112e6cb@posting.google.com> References: <1fwrc5z.1wbucc58vha4aN%stk@snafu.de> <a1ed16f9.0306201135.5802e437@posting.google.com> <1fwyaln.v7pwbouxanswN%stk@snafu.de> NNTP-Posting-Host: 213.23.165.43 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1056483810 2409 127.0.0.1 (24 Jun 2003 19:43:30 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 24 Jun 2003 19:43:30 GMT