Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site unc.UUCP Path: utzoo!linus!decvax!mcnc!unc!tim From: tim@unc.UUCP (Tim Maroney) Newsgroups: net.lang.c Subject: Re: C structure alignment Message-ID: <7096@unc.UUCP> Date: Wed, 11-Apr-84 21:51:42 EST Article-I.D.: unc.7096 Posted: Wed Apr 11 21:51:42 1984 Date-Received: Fri, 13-Apr-84 00:10:56 EST References: <122@ihnet.UUCP> Organization: CS Dept., U. of N. Carolina at Chapel Hill Lines: 21 Excuse me, but you CAN assume that members of a struct appear in the listed order; furthermore, if two structs have a common beginning (that is, their first n members are identical), you can assume that they will be at the same offset. My favorite use of this is writing generic linked list manipulation functions, in which each cell starts with a pointer to the next, and the rest of the cell is a value of arbitrary type. I don't have my K&R handy, but it's in there. There was a discussion about this a few months ago. For a lot of applications, you don't care about the ordering of struct members, and you'd like the compiler to rearrange them for maximum storage efficiency within its alignment requirements. Unfortunately, you can't do that in C. (It would be easy enough to add -- just put a new keyword before the open brace to signal that you don't care about the order -- but then again, what wouldn't?) -- Tim Maroney, The Censored Hacker mcnc!unc!tim (USENET), tim.unc@csnet-relay (ARPA) All opinions expressed herein are completely my own, so don't go assuming that anyone else at UNC feels the same way.