gcc-3.4 complains about non-integers in:
Because i'm using the constants in a lexer, and they can do double duty
for error message printouts. I need to use them multiple places in the
code, and if i use the strings directly, i'm not guaranteed to get the
same pointer value every time.
const char * const IDENTIFIER = "<identifier>";
Now you are guaranteed (and you really don't want to use the string
constant directly anyway, your compiler can't warn against inadvertant
typos that way). Even if your implementation allows something that
questionable, it doesn't guarantee they can be casted back to a string
or even that are distinct values when casted to an integer type. For
what you're trying to do, I would probably do something like:
#define TOKEN(F) \
F(IDENTIFIER, "<identifier>") \
F(WIDGETDEF, "widgetdef")
#define tok(a,b) a = b,
enum Token {
TOKEN(tok)
NUM_TOKENS
};
#undef tok
#define tok(a,b) b,
const char * const token2str[NUM_TOKENS] = {
TOKEN(tok)
};
#undef tok