#defines -> enums?

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


George Greer wrote:
>
> >These are the errors I got:
> >act.other.c: In function `do_gen_tog':
> >act.other.c:966: duplicate case value
> >act.other.c:960: this is the first entry for that value
> >act.other.c:969: duplicate case value
> >act.other.c:963: this is the first entry for that value
>
> Check your #define values.

What about changing all those #defines to enums? Will turn CircleMUD
much more failproof. I did it on my mud.

So...
#define SCMD_NOSUMMON   0
#define SCMD_NOHASSLE   1
#define SCMD_BRIEF      2
#define SCMD_COMPACT    3
#define...

...will became...
enum {
  SCMD_NOSUMMON,
  SCMD_NOHASSLE,
  SCMD_BRIEF,
  SCMD_COMPACT,
  ...
};

No need for numbers. I have changed 98% of all non-macro #defines to
enums. The only ones that was not changed was the MAX_INPUT_LENGTH and
similar. Defines for flags/bits was changed too:

enum {
  ROOM_DARK = (1 << 0),
  ROOM_DEATH = (1 << 1),
  ...
};

TRUE and FALSE constants was changed too

/*
#define FALSE 0
#define TRUE !FALSE
typedef char bool;
 */
typedef enum {
  FALSE,
  TRUE
} bool;

This can lead to some problems, due to the size change (from 8 to 32
bits), but it worked well for me.

Regards,
Juliano.

--
I am not an animal! I am ... well, not an animal.

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