Preprocessor equality test, is this standard?

后端 未结 5 1911
死守一世寂寞
死守一世寂寞 2021-02-05 11:27

I had envisaged one of these in the project preferences

  • TESTING = HOST
  • TESTING = TARGET
5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 11:47

    I had the same problem. It used to be the compiler would error if the #if parameter was not defined which is what I wanted. I learned the hard way this is no longer the case. The solution I came up with is as follows:

    #define BUILDOPT 3
    
    #if 3/BUILDOPT == 1
        
    #endif
    

    If BUILDOPT is not defined you get a compile error for divide by 0. If BUILDOPT != 3 && > 0 the #if fails.

提交回复
热议问题