Boolean in ifdef: is “#ifdef A && B” the same as “#if defined(A) && defined(B)”?

后端 未结 5 412
慢半拍i
慢半拍i 2020-12-13 03:18

In C++, is this:

#ifdef A && B

the same as:

#if defined(A) && defined(B)

?

I was

5条回答
  •  渐次进展
    2020-12-13 03:57

    Conditional Compilation

    You can use the defined operator in the #if directive to use expressions that evaluate to 0 or 1 within a preprocessor line. This saves you from using nested preprocessing directives. The parentheses around the identifier are optional. For example:

    #if defined (MAX) && ! defined (MIN)  
    

    Without using the defined operator, you would have to include the following two directives to perform the above example:

    #ifdef max 
    #ifndef min
    

提交回复
热议问题