macros - C pre-processor defining for generated function names -
i have situation have quite few generated functions, , point them @ generic functions have created (to allow me reuse base code when generated function names change).
essentially, have list of function names follows:
void callback_signalname1(void); void callback_signalname2(void); ...etc
once these generated, define macro allow them called generically. idea this, haven't had luck implementing it...as c pre-processor takes name of macro instead of macro defined as:
#define signal1 signalname1 #define signal2 signalname2 #define function_name(signal) (void callback_ ## signal ## (void)) ... ... function_name(signal1) { .. return; }
the issue receive
void callback_signal1(void)
instead of
void callback_signalname1(void)
is there way around this?
you need provide level of "function-like macro" ensure proper expansion:
e.g.
#define signal1 signalname1 #define signal2 signalname2 #define make_fn_name(x) void callback_ ## x (void) #define function_name(signal) make_fn_name(signal) function_name(signal1) { return; }
output:
$ gcc -e prepro.cc # 1 "prepro.cc" # 1 "<built-in>" # 1 "<command-line>" # 1 "prepro.cc" void callback_signalname1 (void) { return; }
Comments
Post a Comment