🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#806
From: Thorrsten Froehlich
Date: Wed, 25 Jun 2003 18:16
46 lines
3526 bytes
stk@snafu.de (Stefan Haller) wrote in message news:<1fx3x6k.1dzfady1to3r7kN%stk@snafu.de>...
> Thorrsten Froehlich <froetho@charlie.iit.edu> wrote:
> 
> > > 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.
> 
> That's not what I said.  "#pragma options align" does of course control
> the alignment of members of a C++ class.  However, it does not have any
> influence on the padding that is added between a base class and a
> derived class.

Ok, wait a second. I re-read your initial post. So the alignment is
correct, there there must be something else, and looking much closer
suggests there is tail padding for CFM, as specified by "The total
size of a struct or union is rounded up to a multiple of its embedding
alignment" (3.3.1.2 in the CFM ABI spec).

However, the gcc C++ ABI says tail padding should be ignored. It says
"dsize(O): the data size of an object, which is the size of O without
tail padding."  And it further specifies "If D is not an empty base
class or D is a data member: Start at offset dsize(C), incremented if
necessary for alignment to nvalign(D) for base classes or to align(D)
for data members." (2.4 II. in the gcc ABi spec).

So, the CFM struct embedding specification of the base-derived case
uses tail padding, and the Mach-O gcc C++ ABI way is to not use tail
padding (as discussed in
<http://gcc.gnu.org/ml/gcc/2002-08/msg00880.html>).

Now, there is only one way I can imagine that will solve your problem
for everything but charcater arrays (because you cannot apply the
trick to them, unless you make them multiples of four in size and
disable the macro processor trick for them).  I would suggest to use
the macro preprocessor to perform #define bool int, #define char int,
#define short int in the class declarations. This way, everything will
be aligned to four bytes on both ABIs and it should work. Of course,
you don't want to need to do this in your source code.

I suppose in conclusion a feature Metrowerks could add is control over
tail padding ;-)

   Thorsten
Technical Details
Message-ID: <a1ed16f9.0306251016.d894041@posting.google.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail
References: <1fwrc5z.1wbucc58vha4aN%stk@snafu.de> <a1ed16f9.0306201135.5802e437@posting.google.com> <1fwyaln.v7pwbouxanswN%stk@snafu.de> <a1ed16f9.0306241143.5112e6cb@posting.google.com> <1fx3x6k.1dzfady1to3r7kN%stk@snafu.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f635e,98e56c06675247cc
X-Google-Attributes: gidf635e,public
X-Google-Thread: 10bcce,98e56c06675247cc
X-Google-Attributes: gid10bcce,public
X-Google-ArrivalTime: 2003-06-25 11:16:27 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: 25 Jun 2003 11:16:26 -0700
Organization: http://groups.google.com/
Lines: 46
Message-ID: <a1ed16f9.0306251016.d894041@posting.google.com>
References: <1fwrc5z.1wbucc58vha4aN%stk@snafu.de> <a1ed16f9.0306201135.5802e437@posting.google.com> <1fwyaln.v7pwbouxanswN%stk@snafu.de> <a1ed16f9.0306241143.5112e6cb@posting.google.com> <1fx3x6k.1dzfady1to3r7kN%stk@snafu.de>
NNTP-Posting-Host: 213.23.180.19
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1056564987 8732 127.0.0.1 (25 Jun 2003 18:16:27 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: 25 Jun 2003 18:16:27 GMT