Preprocessor equality test, is this standard?

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

I had envisaged one of these in the project preferences

  • TESTING = HOST
  • TESTING = TARGET
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-05 11:59

    And note that you can do this:

    #ifndef TESTING
        ...
    #elif TESTING == HOST
        ...
    #elif TESTING == TARGET
        ...
    #else
        #error "Unexpected value of TESTING."
    #endif
    

    Also:

    #if defined(TESTING) && TESTING == HOST
        ...
    #endif
    

    If you want to collapse the tests. The parenthesis are optional (#if defined TESTING is valid) but I think it's clearer to include them, especially when you start adding additional logic.

提交回复
热议问题