Overzealous alignment and padding

Henry Spencer henry at utzoo.uucp
Sun Oct 16 09:38:28 AEST 1988


In article <410 at sdrc.UUCP> scjones at sdrc.UUCP (Larry Jones) writes:
>I am looking for information about C compilers that are overzealous
>about aligning structure members and padding structures...
>If there are lots of compilers like this ...
>then we're going to have to do a major rethink...

You're going to have to do a major rethink.  Such compilers are indeed
common.  Many compilers pad all structs out to a word boundary just on
general principles.  Some of them actually have important reasons for
doing so:  on any machine where char pointers are a hassle -- Data General
and Cray, to name two -- there is a strong efficiency incentive to pad
all structs out so they can use word pointers.  Life is also much simpler
if all struct pointers share the same representation, which again bites
you if char pointers are different.

>... it makes it impossible to declare a struct that
>conforms to some external format (e.g. records in a file)...

Right.  This can't be done portably in C.  You have to read the data in
as a lump of bytes and then do a component-by-component copy.  (This is
necessary anyway for ints and such, due to byte-ordering problems.  To
say nothing of questions like the size of ints and the representation
of floating point...)

Yes, this is a hassle.
-- 
The meek can have the Earth;    |    Henry Spencer at U of Toronto Zoology
the rest of us have other plans.|uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list