Variables optimized out with g++ and the -Og option(使用 g++ 和 -Og 选项优化的变量)
问题描述
当我使用 -Og 选项使用 g++ 编译我的 C++ 程序时,我看到了 <optimized out> 的变量,而且当前行有时会跳过.这种优化级别的行为是预期的,还是我有一些问题?gcc 的手册页说:
When I compile my C++ program with g++ using the -Og option I see variables that are <optimized out>, and also the current line sometimes skips around. Is this behaviour expected at this optimization level, or do I have some problem? The man page of gcc says:
-Og
优化调试体验.-Og 启用不干扰调试的优化.它应该是标准编辑-编译-调试周期的首选优化级别,提供合理的优化级别,同时保持快速编译和良好的调试体验.
-Og
Optimize debugging experience.-Ogenables optimizations that do not interfere with debugging. It should be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience.
因此我没想到会出现这种行为.在我的系统上,我有 g++ 4.9.2 版和 gdb 7.7.1 版.
hence I did not expect this behaviour. On my system I have g++ version 4.9.2 and gdb version 7.7.1.
推荐答案
这是使用 -Og 选项编译时的正常行为.在此优化级别,只要编译器遵循 as-if 规则.这可能包括删除变量(或转换为常量),以及删除未使用的函数.
This is normal behaviour when compiling with the -Og option. At this optimisation level the compiler is allowed to optimize as long as it adheres to the as-if rule. This could include the removal of variables (or conversion to constants), as well as the dropping of unused functions.
建议要么习惯跳过,要么使用-O0选项进行编译.
The recommendation is either to get used to the skipping or to compile with the -O0option.
这篇关于使用 g++ 和 -Og 选项优化的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 g++ 和 -Og 选项优化的变量
基础教程推荐
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 这个宏可以转换成函数吗? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
