gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 22:05:36 25 4
gpt4 key购买 nike

当我用 g++ 编译我的 C++ 程序时使用 -Og选项我看到的变量是 <optimized out> ,并且当前行有时会跳过。这种优化级别的行为是预期的,还是我有一些问题? gcc 的手册页说:

-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 版。

最佳答案

这是使用 -Og 选项编译时的正常行为。在这个优化级别,只要编译器遵循 as-if rule 就可以进行优化。 .这可能包括删除变量(或转换为常量),以及删除未使用的函数。

建议要么习惯跳过,要么使用-O0选项进行编译。

关于c++ - 使用 g++ 和 -Og 选项优化的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31435771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com