Structure Member Padding

Alan J Rosenthal flaps at dgp.toronto.edu
Sat Jul 14 00:44:07 AEST 1990


daniels at ogicse.ogc.edu (Scott David Daniels) writes:
>This can easily be done by the compiler (it simply keeps track of holes and
>their alignments, and fills them whenever an appropriate (non-array) element
>is added.  The reason for non-array is to allow the existing code that extends
>a struct by adding to a final array at the end to continue to work.

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.  Actually, it would be ok by me for the char to be
placed in different portions of the otherwise-wasted word in the two cases, but
for the behaviour of extending the struct by adding to the count passed to
malloc() to differ in the two cases would be strange.

ajr

p.s. the memcpy-clobber problem is of course more serious.



More information about the Comp.std.c mailing list