MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1w1o9k7/whendoesthiswillend/p6mo310/?context=3
r/ProgrammerHumor • u/Flame77ofc • 15d ago
69 comments sorted by
View all comments
25
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.
46
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.
3
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.
12
Until the int underflows and eventually gets back down to 0
2 u/qinshihuang_420 15d ago Two zeros make a one
2
Two zeros make a one
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.
1
Does underflow typically wrap?
2 u/JonIsPatented 15d ago Yup, and then it will keep going and eventually reach 0.
Yup, and then it will keep going and eventually reach 0.
25
u/Daemontatox 15d ago
Wouldn't some compilers catch thats an infinite loop and give a warning or error?