How can I generate unique values in the C preprocessor?

后端 未结 6 1176
南笙
南笙 2020-11-27 04:54

I\'m writing a bunch of related preprocessor macros, one of which generates labels which the other one jumps to. I use them in this fashion:

MAKE_FUNNY_JUMPI         


        
6条回答
  •  误落风尘
    2020-11-27 05:43

    If you're using GCC or MSVC, there is __COUNTER__.

    Other than that, you could do something vomit-worthy, like:

    #ifndef USED_1
    #define USED_1
    1
    #else
    #ifndef USED_2
    #define USED_2
    2
    /* many many more */
    #endif
    #endif
    

提交回复
热议问题