Hi,
I tried what was suggested under the link you posted but that didn't seem to resolve the issue.
To clarify the above example:
messagenames.h only contains lines containing REGISTER_MESSAGE(messagename), no other code or include guards.
When the preprocessor parses "messages.h" it copy pastes the contents of messagenames.h into where it was included.
Since the macro REGISTER_MESSAGES is defined right above the use, it is defined once it's copy pasted into the enum / array initializer list. For the enum, the macro is defined to simply copy paste the contents of the macro into the enum followed by a comman. For the array, the macro stringizes the arguments of the macro and inserts those strings comma separated.
So after the preprocessor expands the example above the file "messages.h" would look something like this:
#define REGISTER_MESSAGE(x) x,
typedef enum
{
CORE_STARTUP,
CORE_SHUTDOWN,
NUM_MESSAGES
} Messages;
#undef REGISTER_MESSAGE
#define REGISTER_MESSAGE(x) #x,
static char const gMessageNames[] =
{
"CORE_STARTUP",
"CORE_SHUTDOWN",
"Invalid"
};
#undef REGISTER_MESSAGE
The purpose of this trick: stringizing enums. Basically now it's possible to use the enum as both an int (for quick identification of a symbol, say index into a std::map using the enum value), while maintaining an array of corresponding strings.
gMessageNames[CORE_STARTUP] equals "CORE_STARTUP"