使用 g++ 和 -Og 选项优化的变量

Variables optimized out with g++ and the -Og option(使用 g++ 和 -Og 选项优化的变量)
本文介绍了使用 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. -Og enables 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 选项优化的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)