i need write functions this:
void foo() { //some details } enum fun_names { fun_name_foo, }; so made 2 macros:
#define make_fun(fun) void fun(){} #define add_fun(fun) fun_name_##fun, then use them this:
make_fun(foo) make_fun(bar) enum fun_names { add_fun(foo) add_fun(bar) }; but can see, i'm repeating 2 macros same arguments. possible make 1 single macro this?
create_fun(foo) create_fun(bar) this saves lines of codes , less error-prone.
a possible trick might have macro taking macro name argument
#define do_enum(mac) \ mac(foo) \ mac(bar) then
#define declare_enum(x) x, enum fun_names { nothing, do_enum(declare_enum) }; #undef declare_enum and declare functions:
#define declare_fun(x) void myfun_##x(void); do_enum(declare_fun) #undef declare_fun and on.
another way might generate specialized header files, e.g. using awk script, file containing list of functions etc..
Comments
Post a Comment