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

后端 未结 16 1619
感动是毒
感动是毒 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:50

    It's almost (almost) never the compiler.

    First, make sure you're compiling warning-free, with -Wall.

    If that didn't give you a "eureka" moment, attach a debugger to the least optimized version of your executable that crashes and see what it's doing and where it goes.

    5 will get you 10 that you've fixed the problem by this point.

提交回复
热议问题