Elapsed time across rollover

A controller uses a 32-bit unsigned millisecond timestamp that wraps modulo 232=42949672962^{32}=4294967296. A scheduled action uses this test, with all three variables declared as the same 32-bit unsigned type:


C++
if (now - previous >= interval) {
    // Perform the action.
}


The saved timestamp is previous = 4294967271, the current timestamp is now = 39, and interval = 60. The true elapsed time since the saved timestamp is less than one full wrap. Which conclusion is correct?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Delay and Timing Functions Questions: