I'm starting a foray into using macros to generate data structures. Alas, I've run into a strange snag. I want to write the following macro:
#define CREATE_STRUCT(NAME) struct ##NAME { }
I attempt to use it like this:
CREATE_STRUCT(test);
However, it generates an error and the macro expansion apparently doesn't work. I've noticed that in every example of this type of macro expansion I've seen, there is an underscore (_
) that precedes the ##<ARG>
token. For example:
#define CREATE_STRUCT(NAME) struct _##NAME { }
This one works, but of course it throws an underscore at the beginning of the newly declared type.
So, there's a few questions here:
- Is there a way to avoid requiring a character to precede the
##
token? - What are the rules regarding the
##
token in macros?
Thank you in advance!