>>19In the beginning there were only
int
and
char
,
>>25I find that sort of usage annoying since it will trigger "enum constant not covered" warnings in switch statements. One of many annoyances with enums in C... (I'll confess I (ab)use them frequently, solely because it makes it easy to traverse definitions with ctags.)
I prefer this
ENTERPRISE QUALITY ENUM HANDING:
#include <errno.h>
typedef enum { /* yes typedef, I hate typing "enum" */
FOO,
BAR,
BAZ,
QUX,
} meta meta_t; /* and the POSIX committee can bite me */
static void do_foo();
static void do_bar();
static void do_baz();
static void do_qux();
/* ... */
int dispatch_meta(meta_t val)
{
switch (val) {
case FOO:
return do_foo();
case BAR:
return do_bar();
case BAZ:
return do_baz();
case QUX:
return do_qux();
}
return -EINVAL;
}