I've some issues with the following code:
Code: Select all
/**
* @brief Checks if the specified time is within the specified time range.
* @note When start==end then the function returns always true because the
* whole time range is specified.
*
* @param[in] time the time to be verified
* @param[in] start the start of the time window (inclusive)
* @param[in] end the end of the time window (non inclusive)
* @retval true current time within the specified time window.
* @retval false current time not within the specified time window.
*
* @xclass
*/
static inline bool chTimeIsInRangeX(systime_t time,
systime_t start,
systime_t end) {
return (bool)((systime_t)((systime_t)time - (systime_t)start) <
(systime_t)((systime_t)end - (systime_t)start));
}
When end==start this returns always false, but in the comment it say always true.
When end==start this is always 0. time-start is always > 0, because it's unsigned. In that case 1 < 0 is always false?
In my current specific case:
Code: Select all
chTimeIsInRangeX(9682, 9659, 9659)