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 选项优化的变量
基础教程推荐
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
