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

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

c# - MSDN OneNote Api: Navigate to never before opened page without opening a OneNote Application Window -