Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!jimad From: jimad@microsoft.UUCP (JAMES ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: const enums -- Lawyers opinions?? Keywords: const, enum Message-ID: <10197@microsoft.UUCP> Date: 9 Jan 90 19:15:30 GMT References: <963@rna.UUCP> Reply-To: jimad@microsoft.UUCP (JAMES ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 27 cfront 2.0 accepts this with the appropriate warning that you're assigning an int to an enum -- when you or individual bits together you end up with values not in the set original defined in the bits enum -- so how can the receiver of the or results be a "bits" ? The following slight change makes more sense to me, and compiles under cfront 2.0 without warning: enum bit { .... }; typedef int bits; ... bits someresult = one | two | whatever; [not to imply bit or bits are good names to use for these things, nor zero, one, two, ...] Another approach to setting individual bits is to use one or the other Bit, bits, or Bitset classes floating around. The typical trick is to identify individual bits by their shift number, then automagically shift 1 << shiftnum inline using constructors, inline operators, or whatever, to allow a small set of these values to be packed in an int. Since most compilers eval say 1 << 3 to be 8 at compile time, these classes are close to the efficiency offered by the more historical enum approaches.