C structs & A question about octet

Eric Lund eric at sdcrdcf.UUCP
Fri Nov 7 06:10:48 AEST 1986


"The C Programming Language", Kernighan and Ritchie, p. 196: "Each
non-field member of a structure begins on an addressing boundary
appropriate to its type; therefore, there may be unnamed holes in a
structure."

Kernighan and Ritchie say nothing of how big or small the unnamed holes
may be.  I've used one C compiler that byte aligned chars in structs
until it encountered a short, then used even byte alignment until it
encountered a long, and then aligned everything on four byte
boundaries.  There is nothing in the quoted sentence that prevents
anyone from writing a code generator that always aligns every non-field
member on a 4K boundary.

Mayhaps you can use fields for some of your needs, but "Field members
are packed into machine integers; they do not straddle words."
(p. 196), and "... implementations are not required to support any but
integer fields.  Moreover, even int fields may be considered to be
unsigned." (p. 197)  To increase your confidence in predicting the
behavior of the C compiler, p. 212 starts out "Purely hardware issues
like word size...".

(Ever tried sending a raw structure over a heterogeneous network
without benefit of RPC?  Back when you were young and foolish and
didn't know that VAXen and SUNs have different byte orders?  And you
thought that structs were all the same?  You have my sympathies!)


You could name bit types of differing lengths VIII, XVI, and XXXII,
but I don't think that that's what you intend.

					Eric the DBA

Disclaimer: any opinions found herein are mine.  Please return them;
no questions asked.



More information about the Comp.lang.c mailing list