You can do this, but only with an extremely difficult restriction that you must know all type names in advance: it will not work with any custom types unless the user adds them to the list of known types too - admittedly, this is not difficult.
Accepting this restriction, you can do something like this:
#define LPAREN ( #define RPAREN ) #define COMMA , #define CAT(L, R) CAT_(L, R) #define CAT_(L, R) L ## R #define EXPAND(...) __VA_ARGS__ #define SPLIT(OP, D) EXPAND(OP CAT(SPLIT_, D) RPAREN) #define SPLIT_int LPAREN int COMMA #define SPLIT_char LPAREN char COMMA #define SPLIT_float LPAREN float COMMA #define SPLIT_double LPAREN double COMMA #define MY_MACRO(A, B) \ SPLIT(MY_OTHER_MACRO, A); SPLIT(MY_OTHER_MACRO, B); MY_MACRO(int x, char * z)
Adding a type to the list of known types is, as mentioned above, single-line ( #define SPLIT_myType LPAREN myType COMMA ) and can be executed anywhere in the program until it is used before the type is actually used by SPLIT , so this is not the end of light, although he is very intrusive.
There is no easy way to get an asterisk to the left of the split. This could probably be done, but it would have been much more complicated and would have required a restriction on the list of allowed variable names, which IMO is much, much worse. Probably more intrusive, as you almost certainly have more variables than types in your work program.
source share