Structure Member Padding

Doug Gwyn gwyn at smoke.BRL.MIL
Tue Jul 10 12:37:50 AEST 1990


In article <10420 at ogicse.ogc.edu> daniels at ogicse.ogc.edu (Scott David Daniels) writes:
-	struct { short s; char a; };
-	struct { short s; char a, b; };
-	struct { short s; char a, b, c; };
-should all have the same head (that is, the addition of b and c should not
-move where a belongs).

But that has nothing to do with my point; in my example these would
all have compatible layout, including the padding between s and a;
I assumed that chars would not be packed into the same word as the short.

-	struct first { char a; short s; };
-	struct second{ char a; short s; char b; };
-	struct third { char a; char b; short s; };
-I would like to be able to use the same layout for third and second, ...

But if shorts have specific alignment requirements, this is impossible.
(At least, it would impose an unacceptable performance penalty.)



More information about the Comp.std.c mailing list