Subject: Re: CVS commit: basesrc/usr.bin/file
To: None <tech-userlevel@netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-userlevel
Date: 06/05/2002 13:36:56
>> i've heard that some of embedded compilers even reorder members...
>> (maybe it is just for some embedded C compiler, but it worries me)
> Reordering members of a structure is a violation of the C standard

So is int smaller than 8 bits, yet I've seen programs touted as C
compilers that by default do 8-bit ints.  (Targeted at embedded
processors, to be sure; the 8051 is the one I remember.)  Strictly
speaking, such things are not actually C compilers, being instead
almost-but-not-quite-C compilers.  But they're C compilers in much the
same loose way that NetBSD is UNIX.

I've never understood why compilers are prohibited from rearranging
struct members.  As long as it's done deterministically, so as to not
break separate compilation, I can't see any harm in it.  (You would
have to either require that the first member be nailed down, or give up
the guarantee about converting between pointers to structs and pointers
to their first members; I'd prefer the latter.)

> section 6.2.5.20 of C99 requires that members of a structure be
> sequentially allocated

Of course, what does "sequentially allocated" really mean?  I'm
wondering if this can be fudged by the "as if" rule.

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B