bit fields in unions

Joseph S. D. Yao jsdy at hadron.UUCP
Tue Nov 12 10:35:18 AEST 1985


In article <6136 at amdcad.UUCP> sorensen at 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 at seismo.{CSS.GOV,ARPA,UUCP}



More information about the Comp.lang.c mailing list