I've searched around, and have yet to find an example, so I'm thinking maybe it can't be done.
What I want to do is parse an individual argument, like x, passed to a macro.
For instance,
Code:
#define PROTO(x) ........ // <-- my macro
.
.
.
PROTO(static int foo(char *)) ; // a function prototype, wrapped inside a macro.
I want to be able to break x apart into each token, and beyond that, be able to recognize that foo is a function name by the placement of the token after the return type (which might be a pointer), and the fact that there is a left paren at the end of it.
Can this be done with the C macro facility? Basically, I want to substsring x and compare the substringed values to constants.
My overall objective is to generate 2 function prototypes from different compilation units.
In one CU, I just want the standard function prototype to be output:
Code:
static int foo(char *) ;
which is done by merely coding:
However, I also want the following function prototype generated based on other environment characteristics:
Code:
int (* foo)(char 8) ;
In short, the static modifier will be dropped and the function name foo will be converted to function pointer foo.
If this can't be done with the Macro facility, I have already worked out how to do this in an ugly way, by comma-separating the tokens:
Code:
#define PROTO(w,x,y,z) w x y ## z
or
#define PROTO(w,x,y,z) x (* y) ## z
PROTO(static, int, foo, (char *)) ;
and this works fine, but it's kinda/sorta convoluted due to the addition of the commas.