Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site hadron.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!qantel!lll-crg!seismo!rlgvax!hadron!jsdy From: jsdy@hadron.UUCP (Joseph S. D. Yao) Newsgroups: net.lang.c Subject: Re: Portability Question Message-ID: <94@hadron.UUCP> Date: Wed, 27-Nov-85 02:51:58 EST Article-I.D.: hadron.94 Posted: Wed Nov 27 02:51:58 1985 Date-Received: Fri, 29-Nov-85 21:19:48 EST References: <3509@brl-tgr.ARPA> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Organization: Hadron, Inc., Fairfax, VA Lines: 19 Keywords: struct, array, packing Summary: structs are n o t just funny arrays In article <3509@brl-tgr.ARPA> jon@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@seismo.{CSS.GOV,ARPA,UUCP}