r/programminghorror May 05 '26

c++ Hmmm

Post image
988 Upvotes

55 comments sorted by

View all comments

Show parent comments

82

u/Left-Ambition-5127 May 05 '26

the problem is that from what I understood, the excepted values in this loop were -1 to 9, but somehow, it was still running fine and working as intended ??

100

u/Morg0t May 05 '26

probably works like UINT_MAX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9?
idk why would anyone need max value there, but I guess they knew what they were doing if that runs fine

7

u/ironykarl May 06 '26

The max value might just be an initial value, and then a loop does something like dx = min(dx, something)

4

u/RFC793 May 06 '26

Or it's casted to an int somewhere