Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!decwrl!labrea!agate!pasteur!cory.Berkeley.EDU!iverson From: iverson@cory.Berkeley.EDU (Tim Iverson) Newsgroups: comp.lang.c Subject: Re: Optimal structure field ordering Message-ID: <4181@pasteur.Berkeley.Edu> Date: 30 Jun 88 21:43:43 GMT References: <163@navtech.uucp> Sender: news@pasteur.Berkeley.Edu Reply-To: iverson@cory.Berkeley.EDU.UUCP (Tim Iverson) Organization: University of California, Berkeley Lines: 26 Many of you have mentioned that allowing the compiler to reorder the structure would go contrary to the K&R gospel, some even pointed out a few problems this would cause. What I would like to point out is the problem caused already by following the K&R dictum that fields shall be aligned according to type. Forced alignment is fine when you're creating your own data, but when you have to interface directly with hardware or massage foreign binary data into local format, it can force the programmer to abandon the nice bit field and structure abilities of C and resort to bit masks and character arrays to properly address the data. Fortunately, some C compilers have an option to compile with "packed" structures. A new "packed" keyword would be even better, as this would allow the speed of word aligned structs in all but the instances where it is necesary to hand-align the data. As it stands, if you want to pack one struct, then you must pack them all, or none of the "non-packed" modules will be able to properly access the structs in the "packed" module. Hopefully, this feature will be added in the next generation of C, if there ever will be such a beast. - Tim Iverson iverson@cory.Berkeley.EDU ucbvax!cory!iverson