Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!wuarchive!udel!princeton!cs!drh From: drh@cs.Princeton.EDU (Dave Hanson) Newsgroups: comp.std.c Subject: Re: enums and bitfields Message-ID: <2735@rossignol.Princeton.EDU> Date: 14 Sep 90 20:15:09 GMT References: <3119@isaak.isa.de> Organization: Dept. of Computer Science, Princeton University Lines: 27 In article <3119@isaak.isa.de> gutjahr@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.