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!allegra!mit-eddie!think!harvard!seismo!rlgvax!hadron!jsdy From: jsdy@hadron.UUCP (Joseph S. D. Yao) Newsgroups: net.lang.c Subject: Re: bit fields in unions Message-ID: <67@hadron.UUCP> Date: Mon, 11-Nov-85 19:35:18 EST Article-I.D.: hadron.67 Posted: Mon Nov 11 19:35:18 1985 Date-Received: Wed, 13-Nov-85 20:48:08 EST References: <6136@amdcad.UUCP> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Organization: Hadron, Inc., Fairfax, VA Lines: 30 Summary: (a) can't; (b) backwards In article <6136@amdcad.UUCP> sorensen@amdcad.UUCP (Sorensen David) writes: > --------------------------------- > | 14-bit integer | > --------------------------------------------- > | gc | tag1 | either ^ or v | > --------------------------------------------- > | tag2 | 13-bit pointer | > --------------------------------- >struct form { > unsigned int gc : 1; > unsigned int tag1 : 1; > union { > unsigned int number : 14; > struct { > unsigned int tag2 : 1; > unsigned int pointer : 13; > } pval; > } val; > }; (A) Inside a union, you may only use things that can stand outside the union. E.g., int x is OK inside & out; but int x:1 is not. Bit fields must be inside structs. I'm not sure where it says so. (B) If you are on a "little-endian" machine, like a VAX or a PDP-11 (bit 0 is lowest-order), then your order of items above is backwards. -- Joe Yao hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP}