Printing name and value of a macro

前端 未结 11 2646
别跟我提以往
别跟我提以往 2020-12-28 21:46

I have a C program with a lot of optimizations that can be enabled or disabled with #defines. When I run my program, I would like to know what macros have been

11条回答
  •  甜味超标
    2020-12-28 22:18

    I believe what you are trying to do is not possible. If you are able to change the way your #defines work, then I suggest something like this:

    #define ON 1
    #define OFF 2
    
    #define OPTIMIZE_FOO ON
    #define OPTIMIZE_BAR OFF
    
    #define SHOW_DEFINE(val)\
        if(val == ON) printf(#val" is ON\n");\
        else printf(#val" is OFF\n");
    

提交回复
热议问题