GCC: program doesn't work with compilation option -O3

后端 未结 16 1560
感动是毒
感动是毒 2020-12-16 20:12

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

16条回答
  •  粉色の甜心
    2020-12-16 20:43

    The error is in your code. It's likely you're doing something that invokes undefined behavior according to the C standard which just happens to work with no optimizations, but when GCC makes certain assumptions for performing its optimizations, the code breaks when those assumptions aren't true. Make sure to compile with the -Wall option, and the -Wextra might also be a good idea, and see if you get any warnings. You could also try -ansi or -pedantic, but those are likely to result in false positives.

提交回复
热议问题