Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cca!mirror!adelie!munsell!jwf From: jwf@munsell.UUCP (Jim Franklin) Newsgroups: comp.lang.c Subject: sizeof(bit-field structures) Message-ID: <1190@munsell.UUCP> Date: Mon, 17-Aug-87 12:12:07 EDT Article-I.D.: munsell.1190 Posted: Mon Aug 17 12:12:07 1987 Date-Received: Wed, 19-Aug-87 04:20:10 EDT Organization: Eikonix Corp., Bedford, MA Lines: 31 Is the size of a bit-field structure required to be at least sizeof(int)? K&R is vague about this -- all I can find is "Field members are packed into machine integers; they do not straddle words." (p. 196) It doesn't say anything about the size of the resulting structure. As a specific example, consider #include union xtbl_entry { u_short x_entry; struct { u_int x_spare : 5; u_int x_val : 11; } x_bits; }; main () { printf("sizeof(union xtbl_entry) = %d\n", sizeof(union xtbl_entry)); } This prints out 2 on my SUN-3 (Release 3.3). In this case, this is exactly what I wanted - the union of a short int and a bit-field structure. But is this portable? I suspect not, since another compiler might allocate a 32-bit int for struct x_bits. Does ANSI-C address this? ----- {harvard!adelie,{decvax,allegra,talcott}!encore}!munsell!jwf Jim Franklin, Eikonix Corp., 23 Crosby Drive, Bedford, MA 01730 Phone: (617) 663-2115 x415