enums and bitfields
Dave Hanson
drh at cs.Princeton.EDU
Sat Sep 15 06:15:09 AEST 1990
In article <3119 at isaak.isa.de> gutjahr at isa.de (Bernd Gutjahr) writes:
>1. Is it defined wether bitfield of enum types like in e.g.:
>
> enum bool { true, false };
> struct { enum bool flag : 1; } s;
>
> are signed or not ? As I understand it from K&R, enums behave like ints,
> and the sign of sign of int bitfield are implementation-dependent.
according to sec. 3.5.2.1, bit-fields must be int, signed int, or unsigned.
each enum must be compatible with an integer type (sec. 3.5.2.2); if that
type is int, signed int, or unsigned, then the enum is a legal
bit-field type. otherwise it's illegal.
since compilers are free to use different integer types for enums,
using enum bit-fields make your program compiler-dependent.
>2. If enums behave like ints, does this means that either
> - int and enum bitfield are signed
> - int and enum bitfield are unsigned
if the enum is compatible with int, the bit-field is signed;
if the enum is compatible with unsigned, the bit-field is unsigned.
>4. If the behavior of enum bitfields is implementation dependent,
> is it possible the make them unsigned with something like:
> unsigned enum bool flag : 1;
no.
More information about the Comp.std.c
mailing list