Original:
long Timeval::delta(const Timeval& other) const
{
// 2^31 milliseconds is just over 4 years.
long deltaS = other.sec() - sec();
long deltaUs = other.usec() - usec();
return 1000*deltaS + deltaUs/1000;
}
should Be:
long Timeval::delta(const Timeval& other) const
{
// 2^31 milliseconds is just over 4 years.
long deltaS = (long)other.sec() - (long)sec();
long deltaUs = (long)other.usec() - (long)usec();
return 1000*deltaS + deltaUs/1000;
}
Reason:
usec() return uint32_t type, which will result in (1-2) > 0, deltaUs will be wrong!!!
Original: long Timeval::delta(const Timeval& other) const { // 2^31 milliseconds is just over 4 years. long deltaS = other.sec() - sec(); long deltaUs = other.usec() - usec(); return 1000*deltaS + deltaUs/1000; }
should Be: long Timeval::delta(const Timeval& other) const { // 2^31 milliseconds is just over 4 years. long deltaS = (long)other.sec() - (long)sec(); long deltaUs = (long)other.usec() - (long)usec(); return 1000*deltaS + deltaUs/1000; }
Reason: usec() return uint32_t type, which will result in (1-2) > 0, deltaUs will be wrong!!!