Preprocessor equality test, is this standard?

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

I had envisaged one of these in the project preferences

  • TESTING = HOST
  • TESTING = TARGET
5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-05 12:06

    The original C preprocessors required explicit #ifdef validation before using a symbol. It is a relatively recent innovation (perhaps driven by scripting languages like Javascript) to assume that undefined symbols have a default value.

    Why don't you always insure the symbol is defined?:

    #ifndef TESTING
     #define TESTING  (default value)
    #endif
    
    #if TESTING==HOST
      ...
    #elif TESTING==TARGET
     ...
    #else
     ...
    #endif
    

    Alternative, maybe force a selection?:

    #ifndef TESTING
     #error You must define a value for TESTING
    #endif
    

提交回复
热议问题