What concept is being exhibited in this macro wrapping?

后端 未结 1 886
南旧
南旧 2021-01-29 02:23

A bunch of code just got handed over to me and I got baffled by macros in the header. I could not understand what they are for:

#define WRAPPER_MACRO(symbol) sym         


        
相关标签:
1条回答
  • 2021-01-29 03:08

    As @Michael said, we'll need to see the real macros to know for sure. But without them, I'm willing to take a few guesses that might help you out.

    The macro nesting is probably a stringification thing. This bit of code is from a codebase I maintain:

    // As per http://gcc.gnu.org/onlinedocs/cpp/Stringification.html:
    // "If you want to stringify the result of expansion of a macro argument, you
    // have to use two levels of macros."
    #ifndef STRINGIFY
    #define STRINGIFY(s) TOSTRING(s)
    #define TOSTRING(s) #s
    #endif
    

    I'm also guessing your PREFIXED_ANOTHER_SYMBOL macro is doing something similar to this, using the # or ## preprocessor directives to prepend a certain symbol to whatever you feed the macro.

    0 讨论(0)
提交回复
热议问题