c - Use Parameter Name of #define in another #define -
is there way use name of #define parameter #define parameter? example:
#define test 1 #define foo(x) foo_##x #define bar(x) foo(##x) bar(test) where results in:
foo_test not:
foo_1 this doesn't work gives:
pasting "(" , "test" not give valid preprocessing token
there 2 ways avoid evaluation of macro argument. use # (stringize) processing operator or ## (token pasting) operator on it.
try following:
#include <stdio.h> #define test 1 #define foo(x) foo ## x #define bar(x) foo(_ ## x) // prevent evaluation of x ## void foo_1() { printf("%s\n", __function__); } void foo_test() { printf("%s\n", __function__); } int main() { bar(test)(); return 0; }
Comments
Post a Comment