Generating an error if checked boolean macro is not defined

后端 未结 5 1056
后悔当初
后悔当初 2020-12-16 12:25

I have several configuration files each one containing the definition of some boolean macro, to be set to 0 or 1. Then, in my code, I check the value of such a macro to deci

5条回答
  •  Happy的楠姐
    2020-12-16 12:41

    The accepted answer of using function-macros is good, but if you want to keep normal macros - and still use the value of FOO if defined and generate an error otherwise you could do:

    #if FOO / defined(FOO)
    #else
    #endif
    

    If FOO is not defined it will trigger integer division by zero.

提交回复
热议问题