Suppose I have a file I can #include
that defines something like this:
#define GROUP_NUMBER_FOO 42
#define GROUP_NUMBER_BAR 37
I would like to #define
a macro that if invoked like this
GROUPID(FOO)(x);
GROUPID(BAR)(x);
is transformed to
GROUP42_ELEMENT_FOO(x);
GROUP37_ELEMENT_BAR(x);
I am hoping this can be done with token-pasting (as in Nested ## operator in C Preprocessor or How to concatenate twice with the C preprocessor and expand a macro as in "arg ## _ ## MACRO"?) but I can't seem to figure out how to do it.
Something like
#define EXTRACT_GROUP(name) GROUP_NUMBER_##name
#define GROUPID(name) GROUP##EXTRACT_GROUP(name)##_ELEMENT_##name
but if I try using GROUPID(FOO)
then I get an error:
error: pasting ")" and "_ELEMENT_" does not give a valid preprocessing token
(Before someone says "XY problem!" I have some existing awkward APIs I'm trying to adapt to in a more sensible way.)