<small id='HP1n7'></small><noframes id='HP1n7'>

    <bdo id='HP1n7'></bdo><ul id='HP1n7'></ul>

      <legend id='HP1n7'><style id='HP1n7'><dir id='HP1n7'><q id='HP1n7'></q></dir></style></legend>
      1. <i id='HP1n7'><tr id='HP1n7'><dt id='HP1n7'><q id='HP1n7'><span id='HP1n7'><b id='HP1n7'><form id='HP1n7'><ins id='HP1n7'></ins><ul id='HP1n7'></ul><sub id='HP1n7'></sub></form><legend id='HP1n7'></legend><bdo id='HP1n7'><pre id='HP1n7'><center id='HP1n7'></center></pre></bdo></b><th id='HP1n7'></th></span></q></dt></tr></i><div id='HP1n7'><tfoot id='HP1n7'></tfoot><dl id='HP1n7'><fieldset id='HP1n7'></fieldset></dl></div>

        <tfoot id='HP1n7'></tfoot>
      2. GCC:程序不适用于编译选项 -O3

        时间:2023-10-17

          <legend id='TR7O4'><style id='TR7O4'><dir id='TR7O4'><q id='TR7O4'></q></dir></style></legend>

          <small id='TR7O4'></small><noframes id='TR7O4'>

          <i id='TR7O4'><tr id='TR7O4'><dt id='TR7O4'><q id='TR7O4'><span id='TR7O4'><b id='TR7O4'><form id='TR7O4'><ins id='TR7O4'></ins><ul id='TR7O4'></ul><sub id='TR7O4'></sub></form><legend id='TR7O4'></legend><bdo id='TR7O4'><pre id='TR7O4'><center id='TR7O4'></center></pre></bdo></b><th id='TR7O4'></th></span></q></dt></tr></i><div id='TR7O4'><tfoot id='TR7O4'></tfoot><dl id='TR7O4'><fieldset id='TR7O4'></fieldset></dl></div>
          • <bdo id='TR7O4'></bdo><ul id='TR7O4'></ul>

              <tbody id='TR7O4'></tbody>
            <tfoot id='TR7O4'></tfoot>
                1. 本文介绍了GCC:程序不适用于编译选项 -O3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我编写的 C++ 程序在使用优化(选项 -O1、-O2、-O3 等)编译时不起作用(出现分段错误),但是当我使用它时它运行良好无需优化即可编译.

                  I'm writing a C++ program that doesn't work (I get a segmentation fault) when I compile it with optimizations (options -O1, -O2, -O3, etc.), but it works just fine when I compile it without optimizations.

                  错误是否在我的代码中?或者我应该假设这是 GCC 中的一个错误?

                  Is there any chance that the error is in my code? or should I assume that this is a bug in GCC?

                  我的 GCC 版本是 3.4.6.

                  My GCC version is 3.4.6.

                  对于此类问题,是否有任何已知的解决方法?

                  Is there any known workaround for this kind of problem?

                  我的程序优化版和未优化版在速度上有很大差异,所以我真的需要使用优化.

                  There is a big difference in speed between the optimized and unoptimized version of my program, so I really need to use optimizations.

                  这是我原来的函子.一种在没有优化级别的情况下工作正常并在任何级别的优化中引发分段错误的方法:

                  This is my original functor. The one that works fine with no levels of optimizations and throws a segmentation fault with any level of optimization:

                  struct distanceToPointSort{
                      indexedDocument* point ;
                      distanceToPointSort(indexedDocument* p): point(p) {}
                      bool operator() (indexedDocument* p1,indexedDocument* p2){
                          return distance(point,p1) < distance(point,p2) ;
                      }
                  } ;
                  

                  这个在任何级别的优化下都能完美运行:

                  And this one works flawlessly with any level of optimization:

                  struct distanceToPointSort{
                      indexedDocument* point ;
                      distanceToPointSort(indexedDocument* p): point(p) {}
                      bool operator() (indexedDocument* p1,indexedDocument* p2){
                  
                          float d1=distance(point,p1) ;
                          float d2=distance(point,p2) ;
                  
                          std::cout << "" ;  //without this line, I get a segmentation fault anyways
                  
                          return d1 < d2 ;
                      }
                  } ;
                  

                  不幸的是,这个问题很难重现,因为它发生在一些特定的值上.在对一千多个向量中的一个进行排序时,我得到了分段错误,因此这实际上取决于每个向量具有的特定值组合.

                  Unfortunately, this problem is hard to reproduce because it happens with some specific values. I get the segmentation fault upon sorting just one out of more than a thousand vectors, so it really depends on the specific combination of values each vector has.

                  推荐答案

                  既然您发布了代码片段并找到了可行的解决方法(@Windows 程序员的回答),我可以说您正在寻找的是 -ffloat-store.

                  Now that you posted the code fragment and a working workaround was found (@Windows programmer's answer), I can say that perhaps what you are looking for is -ffloat-store.

                  -ffloat-store

                  -ffloat-store

                  不要在寄存器中存储浮点变量,并禁止其他可能改变浮点值是从寄存器还是内存中获取的选项.

                  Do not store floating point variables in registers, and inhibit other options that might change whether a floating point value is taken from a register or memory.

                  此选项可防止在 68000 等机器上出现不需要的超额精度,其中(68881 的)浮点寄存器保持比双精度更高的精度.x86 架构也是如此.对于大多数程序来说,额外的精度只会有好处,但少数程序依赖于 IEEE 浮点的精确定义.在修改这些程序以将所有相关的中间计算存储到变量后,将 -ffloat-store 用于此类程序.

                  This option prevents undesirable excess precision on machines such as the 68000 where the floating registers (of the 68881) keep more precision than a double is supposed to have. Similarly for the x86 architecture. For most programs, the excess precision does only good, but a few programs rely on the precise definition of IEEE floating point. Use -ffloat-store for such programs, after modifying them to store all pertinent intermediate computations into variables.

                  来源:http://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Optimize-Options.html

                  这篇关于GCC:程序不适用于编译选项 -O3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:g++ 4.7.1 编译错误:“strsignal"的类型冲突 下一篇:学习在 Xcode 中编译 C++

                  相关文章

                  1. <i id='AqKNJ'><tr id='AqKNJ'><dt id='AqKNJ'><q id='AqKNJ'><span id='AqKNJ'><b id='AqKNJ'><form id='AqKNJ'><ins id='AqKNJ'></ins><ul id='AqKNJ'></ul><sub id='AqKNJ'></sub></form><legend id='AqKNJ'></legend><bdo id='AqKNJ'><pre id='AqKNJ'><center id='AqKNJ'></center></pre></bdo></b><th id='AqKNJ'></th></span></q></dt></tr></i><div id='AqKNJ'><tfoot id='AqKNJ'></tfoot><dl id='AqKNJ'><fieldset id='AqKNJ'></fieldset></dl></div>

                  2. <legend id='AqKNJ'><style id='AqKNJ'><dir id='AqKNJ'><q id='AqKNJ'></q></dir></style></legend>

                      <tfoot id='AqKNJ'></tfoot>

                      <small id='AqKNJ'></small><noframes id='AqKNJ'>

                        <bdo id='AqKNJ'></bdo><ul id='AqKNJ'></ul>