Is it possible to define a preprocessor macro that will expand in the following way.
MACRO1(x) (y,z,w)
--> MACRO2(x,y,z,w)
Can the expansion of MACRO1
somehow consume the left parenthesis of the list that follows the macro invocation and replace it with MACRO2(x,
so that the preprocessor accepts the result as a valid macro invocation (assuming MACRO2
is defined) and not raise an unterminated argument list
error?
I've tried to do something like this
#define STRANGE_MACRO(...) __VA_ARGS__
#define STRIP_PAREN(...) __VA_ARGS__)
#define PREPEND_AND_APPLY_STRANGE(x) STRANGE_MACRO(x,STRIP_PAREN
Calling it like this:
PREPEND_AND_APPLY_STRANGE(x) (y,z,w)
produces the unerminated argument list
error. Is there a way to make it work?
As for the reason I'd like to have this behavior, it is for esetics, I think it looks better to have macro invocation like this
MACRO1(identifier) (
more
complex
arguments
)
than
MACRO2(identifier,
more
complex
arguments
)
I vould just like the former to be transfromed into the later. If it is not possible within the preprocessor rules, no big deal, I'll live with it, but if it is, I'd like to know the trick.