1

Sorry if this is a really stupid question.

I am trying to track down a bug in some C++. The code works in debug mode, but when I apply optimizations with -03 in the makefile it gives incorrect results.

Is it possible to turn off the optimizations for certain functions in the source so that I can locate which routine it is that is broken?

I'm using g++ with -std=c++11

ppyvabw
  • 141
  • 8
  • very similar to this one: http://stackoverflow.com/questions/4713320/is-there-any-way-to-disable-compiler-optimisation-for-a-specific-line-of-code (visual studio) – Jean-François Fabre Sep 25 '16 at 20:04
  • and why not turn off optimizations everywhere? You do have a DEBUG build, don't you? If not, you should not be asking this question, you should be asking "how do I set up a DEBUG build?" – Mike Nakis Sep 25 '16 at 20:05
  • 2
    Possible duplicate of [How to prevent gcc optimizing some statements in C?](http://stackoverflow.com/questions/2219829/how-to-prevent-gcc-optimizing-some-statements-in-c) – Jean-François Fabre Sep 25 '16 at 20:05
  • you can also explore other options like compiling with clang in debug/release mode or disable some g++ optimizations as with `-fno-strict-aliasing`. – Franck Sep 25 '16 at 20:10
  • You could put the function you want to disable in a separate source file and compile that with different optimization switch – M.M Sep 25 '16 at 23:20

0 Answers0