At what point in the loop does integer overflow become undefined behavior?

后端 未结 12 2230
南方客
南方客 2020-12-07 18:12

This is an example to illustrate my question which involves some much more complicated code that I can\'t post here.

#include 
int main()
{
           


        
12条回答
  •  执念已碎
    2020-12-07 18:45

    One thing your example doesn't consider is optimisation. a is set in the loop but never used, and an optimiser could work this out. As such, it is legitimate for the optimiser to discard a completely, and in that case all undefined behaviour vanishes like a boojum's victim.

    However of course this itself is undefined, because optimisation is undefined. :)

提交回复
热议问题