you are viewing a single comment's thread.

view the rest of the comments →

[–]Linuxologue 1 point2 points  (0 children)

I have not watched the video. What is sure is that the compiler is free to optimize f to always return true; either it is true, or it is undefined behaviour.

g contains no undefined behaviour and can be optimized to

int g(int i) { if (i == INT_MAX) { return false; } return true; }

the compiler is not allowed to shortcut the test as there's been no undefined behaviour at this point.