I would go with uint64_t
as it documents "ticks" as a variable that can not hold negative values and also doubles its range of positive values.
I would go with uint64_t
as it documents "ticks" as a variable that can not hold negative values and also doubles its range of positive values.
int64_t elapsed = (int64_t)(t1 - t0);
And it's very easy to cause disaster with: if ((t1 - t0) > 50) ...
which also succeeds if t1<t0.While it's theoretically possible, using all 64 bits is tricky and very hard to test.
The "can not hold negative values" argument is also weak because a uint does not prevent generating negative values - it only prevents you from knowing that you've generated negative values. Such a state is a bug.
Using a uint only serves to make it harder to test when your system is in an invalid state.
uint64_t ticksOfDuration10ms; // No comment necessary
You'll almost always have a global variable, preprocessor define... or something similar to get the frequency (or time increase per tick), which you should use whenever you have to convert "ticks" to actual physical units. If the actual effective tick rate is visible at many places in your code, both as a symbol name or as a comment, you are most certainly doing something wrong.
(then you'd know it was safe)