Structure padding
Lloyd Kremer
kremer at cs.odu.edu
Fri Apr 14 03:08:46 AEST 1989
In article <124 at paix.ikp.liu.se> pekka at paix.ikp.liu.se (Pekka Akselin [The Mad Midnight Hacker]) writes:
>How about this???
>
>union {
> struct foo {
> char Bar[3];
> char Baz[6];
> char Frotz[4];
> } fred;
> char SomeString[3 + 6 + 4];
>} Strings;
>
>#define bar Strings.Bar
>#define baz Strings.Baz
>#define frotz Strings.Frotz
>
>Would there be padding between the Bar, Baz and Frotz arrays in this case?
First, the constructs Strings.Bar etc. are not valid; it would be
Strings.fred.Bar, and so on.
As to internal padding: within the array, no; within the structure, maybe.
So accessing Bar, Baz, and Frotz within Strings.SomeString may or may not be
equivalent to accessing them as Strings.fred.{member_name}. The presence of
the array within the union has no effect on the compiler's policy regarding
internal padding within structures.
Lloyd Kremer
Brooks Financial Systems
{uunet,sun....}!xanth!brooks!lloyd
More information about the Comp.lang.c
mailing list