title: C comparing times that can overflow
body: <p>I need to detect the overflowing of an <code>unsigned long</code>.</p>
  
  <p>This variable holds the amount of milliseconds since the device is running (it's an Arduino). Doing <code>sizeof(unsigned long)</code>, I have come to see it's indeed a 32-bit number. Now, since it increments every millisecond, which means the device will run for about 49 days before this value overflows.</p>
  
  <p>Since it's for a home system, it isn't really advisable. Now what I'm using the number for, is comparing if the current time is larger than the previous time plus an amount of debouncing.</p>
  
  <pre><code>if(timeChanged + amountOfMs &lt; currentTime){ ... }
  </code></pre>
  
  <p>Needless to say, once overflow occurs this isn't going to work anymore. What's an efficient way to solve this? I've thought about also having a second-timer as well to check if the milliseconds one has overflowed, but in the end I'll have the same problem.</p>