Optimal structure field ordering

Jim Blandy blandy at awamore.cs.cornell.edu
Mon Jun 27 23:31:13 AEST 1988


In article <164 at navtech.uucp> mark at navtech.UUCP (Mark Stevans) writes:
>Some responder pointed out correctly that there is no guarantee in the C
>language that the compiler will preserve your field ordering ...

Hmm.  K&R v1, p. 196 (section 8.5 in the reference manual)
	(ooh, quote K&R, baby!  It's SO SEXY!)

	"Within a structure, the objects declared have addresses which
	 increase as their declarations are read left-to-right."

	(ooh, that was so good!  Now be wishy-washy!)

Now I could be wrong, but that looks like a pretty clear statement on
how C orders structures...

I like the fact that C won't mess with your arrangement -
1) If you want to pack for space, you can.
2) If you need to conform to somebody else's format (in files or
   system calls or functions written in other languages), you can.
I think letting the language decide for you which one was important
would be a mistake.

Using any high-level language will take some control out of your hands,
but C does very little of this;  I like that.
--
Jim Blandy - blandy at crnlcs.bitnet
"insects were insects when man was just a burbling whatsit."  - archie



More information about the Comp.lang.c mailing list