#ifdef DEBUG versus #if DEBUG

后端 未结 3 730
闹比i
闹比i 2021-01-30 16:33

It is unclear to me when using compiler directives which of the below two code snippets is correct/preferred and why. It seems that most developers and Open Source projects I\'v

3条回答
  •  不要未来只要你来
    2021-01-30 16:37

    You are correct. #if DEBUG will not evaluate if DEBUG is defined as 0.

    As for when to use each, you can stick to using #ifdef for anything where you only need to add code if the preprocessor definition is present, such as adding debug logging. If you need to inspect the value and go down different compilation paths, then I would use a 0 or 1. A good example of that is TARGET_IPHONE_SIMULATOR, which is always defined for an iOS project, but only 1 if you’re compiling for the simulator.

提交回复
热议问题