简体   繁体   English

GNU GCC编译器优化和调试

[英]GNU GCC compiler optimization and debug

I have a simple question about Eclipse CDT and GNU GCC compiler. 我有一个关于Eclipse CDT和GNU GCC编译器的简单问题。

The application is compiled in 该应用程序编译在

  • Debug mode, ie, Optimization = None(-O0), Debugging = Maximum(-g3), versus application compiled in 调试模式,即Optimization = None(-O0),Debugging = Maximum(-g3),与应用程序在
  • Optimized mode, ie, Optimization = Maximum(-O3), Debugging = None. 优化模式,即优化=最大值(-O3),调试=无。

Apart from the performance difference, is it guaranteed that the application compiled in these 2 mode generates the exactly same results? 除了性能差异之外,是否可以保证在这两种模式下编译的应用程序都能产生完全相同的结果?

I am about to release the application to the end-users, the application is server based, it handles several multicast data feeds. 我将向最终用户发布该应用程序,该应用程序基于服务器,它处理多个多播数据馈送。 Can anyone offer some advice on which compilation mode I should choose for the final release to its end-users. 任何人都可以向最终用户提供关于我应选择哪种编译模式以最终版本的建议。

Thanks. 谢谢。

It is only guaranteed that your program will produce the same results if your code is fully standards-compliant. 如果您的代码完全符合标准,则只能保证程序会产生相同的结果。 There are many ways you can write code that has "undefined behaviour" that actually works on an unoptimized build, but may break when optimized. 您可以通过多种方式编写具有“未定义行为”的代码,这些代码实际上可以在未优化的构建中使用,但是在优化后可能会中断。

For example, suppose I have: 例如,假设我有:

struct A
{
   int i;
};

struct B
{
   int i;
};

int main()
{
    A a;
    a.i = 10;
    B* b = reinterpret_cast<B*>(&a);
    std::cout << b->i << std::endl;
    return 0;
}

This will almost certainly print out 10, but a compiler could legitimately generate code that does something else due to strict aliasing rules 这几乎肯定会打印出10,但是由于严格的别名规则 ,编译器可以合法地生成可以执行其他操作的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM