Closed
Description
Following
Regarding 2:
(@TD-er)
I guess we have to try then what the compiler makes of it.
As far as I know(current - _start)
will give a high value if_start
>current
.
So then the division should also be a high number.
If the compiler should make it a signed integer and then casting it to uint, then we have other issues.
I made some test with gcc and it seems OK.
However, I totally agree it is not clear enough.
To ensure we stay within (unsigned) timeType
bounds (with implicit modulo over range), I would propose to change
unsigned long n = (current - _start) / _timeout
to
unsigned long n = ((timeType)(current - _start)) / _timeout
Also, regarding 1)
return (!_neverExpires) && ((internalUnit - _start) >= _timeout);
to
return (!_neverExpires) && (((timeType)(internalUnit - _start)) >= _timeout);
This is supposed to be already implicit but it becomes clear and explicit this way, what do you think ?
and finally to add somewhere (a proposal from @devyte)
static_assert(std::is_unsigned<timeType>::value == true);
Metadata
Metadata
Assignees
Labels
No labels