I know that the value returned by the `timeGetTime` function wraps around to 0 every 2^32 milliseconds, which is about 49.71 days as the official doc says. So is it possible (however, it is very unlikely) that the delta will be a negative number (when the `newtime` will pass the "magic" 2^32 milliseconds barrier). Lets take for an example VERY unlikely but theoretically possible case:
So there is of course a resulting a negative numer (`-2147481343`) so on the fiest look it won't work here. BUT the compiler will make here an implicit conversion from signed to unsigned resulting in:
while (2147485952 >= MS_PER_UPDATE) {...}
and finally the code WILL work! (thanks to this implicit conversion)
And here is my question. Is it ok/safe to let the code be simple like that and just rely on the implicit conversion made automatically OR maybe I have to take care of the "wrap around" problem myself doing some extra checking/coding?
P.S
If I cannot count on that automatically implicit conversion is it a good solution to just change the operand order when there is about to be an negative delta like below?:
Have you considered using s different time function? The C++ standard library has <chrono> that pretty much fits what you're doing directly without the restriction that concerns you.
the basic thing is if you use an unsigned 64 bit timer, it will cycle to zero much less often.
if the counter were in cpu clocks and ran at 3 billion per second (3 ghz roughly), you get approximately 6 billion seconds before it wraps. I think that is about 70K days of high res ticks, and of course if you measure MS or something other than cpu ticks, it will run many years instead of lots of days... orders of magnitude more days.
Just figure out how long you want to run between restarts/reboots/whatever and math out how to deal with it. Systems that run a few years without a reboot are rare, but they do exist... VERY few do this for many decades on end, though. 70k days is about 200 years.
** pardon if I botched any rough math there. I did all that in my head so its very rough.