[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: enum may be signed

From: Tom Tromey
Subject: Re: enum may be signed
Date: Mon, 03 May 2010 11:04:41 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

>>>>> "Stefan" == Stefan Monnier <address@hidden> writes:

Stefan> Interesting.  I didn't know about that part of the C language.  Is it
Stefan> possible to specify that this is an unsigned enum somehow?
Stefan> I've tried "enum symbol_redirect redirect : 3;" but at least GCC didn't
Stefan> like it.
Stefan> Of course we can add one more bit (we have plenty of bits left there),
Stefan> but I'd first like to know how this is usually handled, since it seems
Stefan> to imply that MSVC always requires one extra bit to store enums.

GCC and GDB do something like this:

/* Be conservative and use enum bitfields only with GCC.
   This is copied from gcc 3.3.1, system.h.  */

#if defined(__GNUC__) && (__GNUC__ >= 2)
#define ENUM_BITFIELD(TYPE) unsigned int

Used like:

struct main_type
  /* Code for kind of type */

  ENUM_BITFIELD(type_code) code : 8;

Continuing to use an enum bitfield on gcc is nice, because gcc will warn
if the enum is too large to fit in the bitfield.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]