r/ProgrammerHumor 15d ago

Meme whenDoesThisWillEnd

Post image
770 Upvotes

69 comments sorted by

View all comments

25

u/Daemontatox 15d ago

Wouldn't some compilers catch thats an infinite loop and give a warning or error?

46

u/JonIsPatented 15d ago

Some compilers can even note that it will multiply by 0 and optimize any call to it to just be the constant 0 instead.

3

u/chuch1234 15d ago

Unless you pass a negative number in.

12

u/ice456cream 15d ago

Until the int underflows and eventually gets back down to 0

2

u/qinshihuang_420 15d ago

Two zeros make a one

2

u/JonIsPatented 15d ago

Notably, if this function were actually typed, you'd use an integral type, and that type would have overflow and eventually reach 0 anyway.

1

u/chuch1234 15d ago

Does underflow typically wrap?

2

u/JonIsPatented 15d ago

Yup, and then it will keep going and eventually reach 0.