Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: notesfiles Path: utzoo!watmath!clyde!floyd!harpo!decvax!ucbvax!ucbcad!ucbesvax.turner From: turner@ucbesvax.UUCP Newsgroups: net.lang.c Subject: Re: enum, bit fields, cpp... Message-ID: <4800038@ucbesvax.UUCP> Date: Wed, 1-Feb-84 04:27:00 EST Article-I.D.: ucbesvax.4800038 Posted: Wed Feb 1 04:27:00 1984 Date-Received: Fri, 2-Mar-84 06:31:18 EST References: <4800037@ucbesvax.UUCP> Organization: UC Berkeley, EE/SESM Lines: 28 Nf-ID: #R:ucbesvax:4800037:ucbesvax:4800038:000:1203 Nf-From: ucbesvax!turner Feb 29 01:27:00 1984 Perhaps there should also be a "bitsizeof" in addition to "sizeof". Defining number of bits per byte (#define NBBY in some places) is not good enough for machines whose byte does not evenly divide the bit- length all scalar types. Thus, with enum types cleaned up the way they ought to be (hope, pray) one could say "bitsizeof (enum foo)" for various ultra-hacky purposes. Even, I would hope, typedef enum { north, south, east, west } direction; struct { ... bool flag: bitsizeof (bool); /* (dumb, since always == 1) */ direction dir: bitsizeof (direction); /* pack next to flag */ ... Hmmm, this seems fraught with terrors for compiler-writers, somehow. Are enums always int-sized (or better, rounded to short or char as appropriate) when used alone? In which case, are their bitsizeof's always that of the primitive scalars they fit into? Or should bitsizeof always mean "minimum number of bits required to represent this scalar type? That would at least be consistent. Having enums be always packed when they are members of structures is also possible, but possibly confusing as well. Or are there other solutions to this whole mess? --- Michael Turner (ucbvax!ucbesvax.turner)