Re: #defines -> enums?

From: Juliano Ravasi Ferraz (jferraz@linkway.com.br)
Date: 08/14/01


Mike Breuer wrote:
>
> >enum {
> >  ROOM_DARK = (1 << 0),
> >  ROOM_DEATH = (1 << 1),
> >  ...
> >};
>
> I would use caution in converting anything that might go into a bitvector,
> especially if you eventually plan to expand it beyond the size of an
> integer (32 bits for most of us).

If you plan to expand beyond the limit of 32 bits, you will need a
compiler capable on handling long long variables. Those compilers (as
far as I know) expands the enum type storage size automatically. Try it:

#include "stdio.h"
void main(void) {
  enum { AA = 0, AB, AC } first;
  enum { BA = (1LL << 40), BB, BC } second;
  printf("First enum has a size of %d bits.\n", sizeof(first)*8);
  printf("Second enum has a size of %d bits.\n", sizeof(second)*8);
}

It gave to me (egcs-2.91.66):

First enum has a size of 32 bits.
Second enum has a size of 64 bits.

I don't know the behavior on other compiler capable on handling 64 bit
variables. Also for the C99 standard.

[]s
Juliano.

--
This isn't right. This isn't even wrong.

--
   +---------------------------------------------------------------+
   | 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