Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Overzealous alignment and padding Message-ID: <1988Oct15.233828.27414@utzoo.uucp> Organization: U of Toronto Zoology References: <410@sdrc.UUCP> Date: Sat, 15 Oct 88 23:38:28 GMT In article <410@sdrc.UUCP> scjones@sdrc.UUCP (Larry Jones) writes: >I am looking for information about C compilers that are overzealous >about aligning structure members and padding structures... >If there are lots of compilers like this ... >then we're going to have to do a major rethink... You're going to have to do a major rethink. Such compilers are indeed common. Many compilers pad all structs out to a word boundary just on general principles. Some of them actually have important reasons for doing so: on any machine where char pointers are a hassle -- Data General and Cray, to name two -- there is a strong efficiency incentive to pad all structs out so they can use word pointers. Life is also much simpler if all struct pointers share the same representation, which again bites you if char pointers are different. >... it makes it impossible to declare a struct that >conforms to some external format (e.g. records in a file)... Right. This can't be done portably in C. You have to read the data in as a lump of bytes and then do a component-by-component copy. (This is necessary anyway for ints and such, due to byte-ordering problems. To say nothing of questions like the size of ints and the representation of floating point...) Yes, this is a hassle. -- The meek can have the Earth; | Henry Spencer at U of Toronto Zoology the rest of us have other plans.|uunet!attcan!utzoo!henry henry@zoo.toronto.edu