Portability Question

Joseph S. D. Yao jsdy at hadron.UUCP
Wed Nov 27 17:51:58 AEST 1985


In article <3509 at brl-tgr.ARPA> jon at cit-vax.arpa (Jonathan P. Leech) writes:
>    If I declare structures containing only one  data  type  (doubles)
>	like this:
>    struct a { double pt[3], color[3]; };
>    struct b { double pt[3], color[3], normal[3]; };
>    is it safe	to  assume  that  they	are  equivalent  in  terms  of
>	alignment and size to arrays of equivalent contents, i.e.
>    double a_dummy[6], b_dummy[9];

In a word, no.  Packing of data types is not defined between elements
of a structure.  It happens to work that way on almost every system
architecture I can think of; but let's posit something silly, like
a 24-bit word alignment with 36-bit doubles and 12-bit byte addressing.
Then words are at 0,2,4,6 bytes; doubles may fold in at 0,3,6,9
bytes; your first struct would have doubles at 0,3,6,10[alignment!],
13,16 bytes instead of 0,3,6,9,12,15 bytes as in the array.
-- 

	Joe Yao		hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}



More information about the Comp.lang.c mailing list