Structure Member Padding

Karl Heuer karl at haddock.ima.isc.com
Thu Jul 12 07:57:57 AEST 1990


In article <13321 at smoke.BRL.MIL> gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
>[Mark's] argument about struct member alignment seems correct, but it raises
>a problem with
>	struct { short s; char a, b, c; };
>on a word-addressed architecture, if short is made a half-word.  Note that
>your line of argument would lead to the conclusion that there can be no
>padding before the first char, but in such a situation a half-word of
>padding would be necessary.

I don't get it.  Why should a half-word of internal padding be necessary or
desirable?  Looks to me like the obvious implementation is to make it a
two-word struct, with the first word containing s and a and b, and the second
word containing c and three pad bytes.  What's the problem?

Karl W. Z. Heuer (karl at kelp.ima.isc.com or ima!kelp!karl), The Walking Lint



More information about the Comp.std.c mailing list