Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!maverick.ksu.ksu.edu!unmvax!bbx!bbxsda!scott From: scott@bbxsda.UUCP (Scott Amspoker) Newsgroups: comp.std.c Subject: Re: Size of structure containing char fields Message-ID: <933@bbxsda.UUCP> Date: 3 Aug 90 18:00:24 GMT References: <1030@lzaz.ATT.COM> <8631@cognos.UUCP> Reply-To: scott@bbxsda.UUCP (Scott Amspoker) Organization: Basis International, Albuquerque, NM Lines: 34 In article <8631@cognos.UUCP> jimp@cognos.UUCP (Jim Patterson) writes: >In article <1030@lzaz.ATT.COM> bds@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