Is it possible for C preprocessor macros to contain preprocessor directives?

后端 未结 7 1294
醉话见心
醉话见心 2020-12-08 19:33

I would like to do the equivalent of the following:

#define print_max(TYPE) \\
#  ifdef TYPE##_MAX \\
     printf(\"%lld\\n\", TYPE##_MAX); \\
#  endif

prin         


        
7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 20:10

    I don't think it's a case of the ## operator not being allowed in an #ifdef. I tried this:

    #define _print_max(TYPE) \
    #ifdef TYPE \
    printf("%lld\n", _TYPE); \
    #endif
    
    #define print_max(TYPE) _print_max(MAX##_TYPE)
    
    
    void main() 
    {
        print_max(INT)
    }
    

    and it still didn't work (it didn't like #ifdef TYPE). The problem is that #ifdef will only accept #defined symbols, not #define arguments. Those are two different things.

提交回复
热议问题