Structure Member Padding

bob larson blarson at dianne.usc.edu
Sat Jul 14 16:15:59 AEST 1990


In article <1990Jul13.104407.29078 at jarvis.csri.toronto.edu> flaps at dgp.toronto.edu (Alan J Rosenthal) writes:
>For:
>	struct { int i; char c; } var;
>and
>	struct { int i; char c[1]; } var;
>to have different layouts, indeed different semantics with respect to layout,
>would be quite bizarre.

Prime's C compiler stores char variables in the right half of a 2-byte
"halfword", and character arrays are packed and start at the left.
This does break code that makes assumptions about unions or that no
padding is between individually declared chars in a structure.
As far as I know, they havn't changed this behavor in their beta-test
ansi compiler.

union {
    struct { char a, b, c, d;} x;
    char y[4];
}

Code that assumes that x.a is the same as y[0] and x.d is y[3] will not
work on prime's c compiler.  note that &a+1 != &b
Bob Larson (blars)	blarson at usc.edu			usc!blarson
	Hiding differences does not make them go away.  Accepting
	differences makes them unimportant.
To join Prime computer mailing list:	info-prime-request at ais1.usc.edu



More information about the Comp.std.c mailing list