Printing name and value of a macro

前端 未结 11 2640
别跟我提以往
别跟我提以往 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:08

    Why not simply testing it with the preprocessor ?

     #if defined(X)
          printf("%s is defined and as the value %d\n", #X, (int)X);
     #else
          printf("%s is not defined\n", #X);
     #endif
    

    One can also embed this in another test not to print it everytime:

     #if define(SHOW_DEFINE)
     #if defined(X)
          printf("%s is defined and as the value %d\n", #X, (int)X);
     #else
          printf("%s is not defined\n", #X);
     #endif
     #endif
    

提交回复
热议问题