Size of structure containing char fields

Scott Amspoker scott at bbxsda.UUCP
Sat Aug 4 04:00:24 AEST 1990


In article <8631 at cognos.UUCP> jimp at cognos.UUCP (Jim Patterson) writes:
>In article <1030 at lzaz.ATT.COM> bds at lzaz.ATT.COM (Bruce Szablak) writes:
>>Given a structure that contains only char fields (possibly unsigned):
>>
>>	struct example1 { char a, b, c; };
>>
>>is ANSI restrictive enough [;-)] to force sizeof(example1) to be 3?
>>Is anyone aware of existing compilers for which this wouldn't be true?
>
>Sun's C compiler on a Sun 3 (with Sun OS 4.0) aligns structs on two
>byte boundaries....
>Another compiler that uses a constant 2-byte alignment rule is the
>Data General MV-series C compiler....

Interesting.  We dynamically allocate different structures back-to-back
in a common memory arena.  Some structures require word alignment and
some don't.  For a long time we simply used sizeof() to allocate the
next structure (we ran on many different machines without any problem).

We finally ran into an implementation that did not pad the character 
structures and got zapped when they got sandwhiched in between other 
structures that required alignment.  (We solved the problem by aligning 
the sizeof() in our code which is a constant expression folded at compile 
time).

The point is, for many years, systems that did *not* pad character
structures seemed to be the mavericks.  Today, I don't know.
We have it set up so we don't care anymore.

-- 
Scott Amspoker
Basis International, Albuquerque, NM
(505) 345-5232
unmvax.cs.unm.edu!bbx!bbxsda!scott



More information about the Comp.std.c mailing list