Re: #defines -> enums?

From: Artovil (artovil@arcanerealms.org)
Date: 08/14/01


At 13:44 2001-08-14 -0500, you wrote:
> > enum {
> >   ROOM_DARK = (1 << 0),
> >   ROOM_DEATH = (1 << 1),
> >   ...
> > };
>
>Why not do..
>
>enum {
>    ROOM_DARK, ROOM_DEATH, ...
>};
>
>[same for -all- other bitflags]
>
>and
>
>#define AND_BITS(x, y) ((x) & (y))
>#define OR_BITS(x, y) ((x) | (y))
>#define XOR_BITS(x, y) ((x) ^ (y))
>#define INV_BITS(x, y) (~(x))
>#define GET_BITS(x) (1 << (x))
>
>#define IS_SET(x, y) (AND_BITS(x, GET_BITS((y))))
>#define REMOVE_BIT(x, y) ((x) = AND_BITS(x, INV_BITS(GET_BITS(y))))
>#define SET_BIT(x, y) ((x) = OR_BITS(x, GET_BITS(y)))
>#define TOGGLE_BIT(x, y) ((x) = XOR_BITS(x, GET_BITS(y)))

Oooh, I like this, even though I am not a low-level code grinder.  I like
the way it is structured.  It is simple, and easy to understand.  I cannot
account for speed or programmability, but I am sure that George, Peter, and
the others will have more to say on that part.

Regards,
/Torgny

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/06/01 PST