How do I make an infinite empty loop that won't be optimized away?

前端 未结 13 1475
后悔当初
后悔当初 2020-12-23 13:16

The C11 standard appears to imply that iteration statements with constant controlling expressions should not be optimized out. I\'m taking my advice from this answer, which

13条回答
  •  没有蜡笔的小新
    2020-12-23 13:39

    I'm sorry if this is absurdly not the case, I stumbled upon this post and I know because my years using Gentoo Linux distro that if you want the compiler to not optimize your code you should use -O0(Zero). I was curious about it, and compiled and ran the above code, and the loop do goes indefinitely. Compiled using clang-9:

    cc -O0 -std=c11 test.c -o test
    

提交回复
热议问题