Redian新闻
>
g++编译时加了优化代码选项是不是会改变代码顺序?
avatar
g++编译时加了优化代码选项是不是会改变代码顺序?# Unix - 噫吁兮,危乎高哉
s*s
1
无意中发现的,gdb调试
如果有-O2,用gdb调试时,逐行执行和源文件顺序不是完全一致
如果不用优化选项,还是一致的。
avatar
c*n
2
sure, never combine "-g" with "-O*".

that's how it optimized your code.

【在 s*****s 的大作中提到】
: 无意中发现的,gdb调试
: 如果有-O2,用gdb调试时,逐行执行和源文件顺序不是完全一致
: 如果不用优化选项,还是一致的。

avatar
e*m
3
You could/should combine them together in a lot of case.
you could then stripe the informtion if you need.

【在 c****n 的大作中提到】
: sure, never combine "-g" with "-O*".
:
: that's how it optimized your code.

avatar
c*n
4
can I ask you when you should have to combine them?

【在 e****m 的大作中提到】
: You could/should combine them together in a lot of case.
: you could then stripe the informtion if you need.

avatar
a*e
5
when you need to make sure the compiler works correctly when
these two options are used together. LOL.

【在 c****n 的大作中提到】
: can I ask you when you should have to combine them?
avatar
c*r
6
when you are using GNU CC and want to debug optimized programs.

【在 c****n 的大作中提到】
: can I ask you when you should have to combine them?
avatar
c*r
7

Read the gcc manual:
"Unlike most other C compilers, GCC allows you to use -g with -O.
The shortcuts taken by optimized code may occasionally produce sur-
prising results: some variables you declared may not exist at all;
flow of control may briefly move where you did not expect it; some
statements may not be executed because they compute constant
results or their values were already at hand; some statements may
execute in different places because they were moved out of loops."

【在 s*****s 的大作中提到】
: 无意中发现的,gdb调试
: 如果有-O2,用gdb调试时,逐行执行和源文件顺序不是完全一致
: 如果不用优化选项,还是一致的。

avatar
c*n
8
looks weird, it's surely that one can combine two options together
and get no error. but what's the benefit from this combination? Do
we really need to dubug a optimized code???

【在 c*r 的大作中提到】
:
: Read the gcc manual:
: "Unlike most other C compilers, GCC allows you to use -g with -O.
: The shortcuts taken by optimized code may occasionally produce sur-
: prising results: some variables you declared may not exist at all;
: flow of control may briefly move where you did not expect it; some
: statements may not be executed because they compute constant
: results or their values were already at hand; some statements may
: execute in different places because they were moved out of loops."

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。