2 ms·
It's a little complicated to see the key point, but what happens is: * The loop in f1 guaranteed to overflow int i if it's executed, but that's undefined behav
by lupire 6y ago
It's a little complicated to see the key point, but what happens is:
* The loop in f1 guaranteed to overflow int i if it's executed, but that's undefined behavior.
* Compilers sometimes delete code with undefined behavior, since that's the most efficient possible implementation.
* Deleting undefined behavior leaves an empty function.
* (Bug?) Empty function gets optimized a way to completely nothing, not even "enter and then exit".
Edit: This comment explains the "missing exit" better. https://news.ycombinator.com/item?id=26499110 https://news.ycombinator.com/item?id=26499110
* Bug: the empty function f1 gets an address anyway, but 0 code; which makes execution fall through to whatever's next; in this case, it's f2's implementation.
* So, calling f1 jumps to the address where f2 is, and f2 runs, which isn't what you want.
"Format your hard drive" just means that "call an arbitrary different function".
- karmakaze 6y agoWith the cloud/github/etc now, 'format your hard drive' is not what it used to be.
- deleted 6y ago[deleted]
- AdamJacobMuller 6y agoThanks for the explanation. When I saw this originally a few hours ago I went to the comments to see what was going on, but, you weren't here yet and I was disappointed :)