C pre-processor defining for generated function names

后端 未结 1 1750
春和景丽
春和景丽 2020-12-09 16:48

I have a situation where I have quite a few generated functions, and would like to point them at some generic functions that I have created (to allow me to reuse the base co

相关标签:
1条回答
  • 2020-12-09 17:39

    You need to provide an extra level of "function-like macro" to ensure the 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;
    }
    
    0 讨论(0)
提交回复
热议问题