Determine optimization level in preprocessor?

后端 未结 2 1331
甜味超标
甜味超标 2020-12-17 09:10

-Og is a relatively new optimization option that is intended to improve the debugging experience while apply optimizations. If a user selects -Og,

2条回答
  •  感情败类
    2020-12-17 09:50

    I believe this is not possible to know directly the optimization level used to compile the software as this is not in the list of defined preprocessor symbols

    You could rely on -DNDEBUG (no debug) which is used to disable assertions in release code and enable your "debug" code path in this case.

    However, I believe a better thing to do is having a system wide set of symbols local to your project and let the user choose what to use explicitly.:

    • MYPROJECT_DNDEBUG
    • MYPROJECT_OPTIMIZE
    • MYPROJECT_OPTIMIZE_AGGRESSIVELY

    This makes debugging or the differences of behavior between release/debug much easier as you can incrementally turn on/off the different behaviors.

提交回复
热议问题