确定preprocessor优化级别? [英] Determine optimization level in preprocessor?

查看:118
本文介绍了确定preprocessor优化级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-oG 是旨在改善调试体验,同时进行优化一个较新的优化选项。如果用户选择了 -oG ,那么我想我的源文件来激活备用code路径来增强调试体验。 GCC提供 __ __ OPTIMIZE preprocessor宏观,但它只有在优化实际上是设置为1。

-Og is a relatively new optimization option that is intended to improve the debugging experience while apply optimizations. If a user selects -Og, then I'd like my source files to activate alternate code paths to enhance the debugging experience. GCC offers the __OPTIMIZE__ preprocessor macro, but its only set to 1 when optimizations are in effect.

有没有学习的优化级别,如 -O1 -O3 或<$ C $方式C> -oG ,用于与preprocessor用?

Is there a way to learn the optimization level, like -O1, -O3 or -Og, for use with the preprocessor?

推荐答案

我相信这是不可能直接知道用来编译软件的优化级别,因为这不是的定义preprocessor符号列表

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

您可以依靠 -DNDEBUG (没有调试),这是用来关闭在发布code断言和启用调试code路径这种情况下。

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

  • 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.

这篇关于确定preprocessor优化级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆