Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.std.c Subject: Re: Size of structure containing char fields Message-ID: <3775@auspex.auspex.com> Date: 28 Jul 90 17:36:50 GMT References: <1030@lzaz.ATT.COM> <8631@cognos.UUCP> Organization: Auspex Systems, Santa Clara Lines: 25 >Sun's C compiler on a Sun 3 (with Sun OS 4.0) aligns structs on two >byte boundaries. This is NOT an ANSI-compatible compiler, but I don't >think that the ANSI standard will force them to change their ways. My >guess is that the implementation was done this way simply because it >was easier. It was done that way because the Sun compiler was ultimately based on the PCC port to the 68K done at MIT, and I think those porters decided to impose only two-byte alignment on 4-byte data types - after all, it's not as if Motorola was ever going to come out with a full-blown 32-bit chip in the 68K family that would run faster with 4-byte alignment, right? :-( I think other 68K C compilers, at least for UNIX systems, do the same. >Interestingly, with the Sun 4, your struct in fact has a size of 3, >even though the Sun 4 generally has more strict alignment rules than >the Sun 3. Actually, there is one case where the Sun-4 compiler has *less* strict alignment rules than the Sun-3 compiler. The MIT compiler also made the minimum alignment requirement for a structure 2-byte alignment, while most other PCC-based compilers, including Sun's SPARC compiler, impose no minimum alignment requirement on structures beyond the most restrictive alignment requirement of the structure's members.