Structure padding

Svante Lindahl zap at front.se
Thu Apr 6 21:14:48 AEST 1989


Consider a struct consisting of a few character arrays, for example:

	stuct foo {
	    char bar[3];
	    char baz[6];
	    char frotz[4];
	} fred;

I need to know if I can safely assume that there will not be any
padding between the arrays.  I didn't think that this would be OK to
assume, but I've tried this with a few different machine and compiler
combos (Sun3/SunOS3.5+(cc|gcc), Sun4/SunOS4.0+cc, Pyramid9820/
OSx4.1+cc (%)) and none of them place any padding between the arrays.
--
% Pyramid's cc is not based on pcc.

(Note: I'm not talking about padding at the end of the struct; there
will often be padding after the last array to make the size of the
struct be a multiple of 2 or 4 bytes.)

-- 
Svante.Lindahl at front.se	 (path-net: uunet!front.se!svante)
			 (non-mx: Svante.Lindahl%front.se at uunet.uu.net)



More information about the Comp.lang.c mailing list