Printing name and value of a macro

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

    #ifdef MYMACRO
      printf("MYMACRO defined: %d\r\n", MYMACRO);
    #endif
    

    I don't think what you are trying to do is possible. You are asking for info at runtime which has been processed before compilation. The string "MYMACRO" means nothing after CPP has expanded it to its value inside your program.

提交回复
热议问题