type and size of bit-fields

Chris Torek torek at elf.ee.lbl.gov
Mon Mar 18 08:01:26 AEST 1991


In article <12638 at adobe.UUCP> taft at adobe.COM writes:
>The ANSI C standard states: "A bit-field is interpreted as an integral type
>consisting of the specified number of bits." Based on this, one might expect
>foo to be treated as a 24-bit integer. That is, in this context, "int" means
>"integral type", not "16-bit integer".

>However, this interpretation may be contradicted by an earlier statement
>that the width of a bit-field "shall not exceed the number of bits in an
>ordinary object of compatible type." This statement is somewhat enigmatic,
>since it depends on what you think is meant by "compatible type" in this
>instance.

There is no contraction here (just a bit of confusing language).  What this
means is that there are various ways to declare bitfields:

	int <name>:<size>;
	signed int <name>:<size>;
and	unsigned int <name>:<size>;

where <size> is `small enough'.  The last two produce signed and
unsigned values that are exactly <size> bits long, while the first one
produces either signed or unsigned, at the implemention's discretion.
`Small enough' here means that the <size> should be no larger than the
number of bits in a `signed int' or `unsigned int', whichever is the
`compatible type' (to use the phrase quoted above, and thus define it
implicitly [I hope]).
-- 
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427)
Berkeley, CA		Domain:	torek at ee.lbl.gov



More information about the Comp.lang.c mailing list