4

For homework, I am writing a program that deals with a lot of time_t objects. I thought about checking them for overflow, but then it occurred to me that if they overflowed we would all be in a might bit of trouble.

Is there a plan for this? What will happen when the time since epoch exceeds storage?

Ziggy
  • 21,845
  • 28
  • 75
  • 104
  • 1
    I doubt there are any mainstream CRT implementations left that haven't made time_t a 64-bit type. – Hans Passant Jan 31 '12 at 05:27
  • 1
    http://en.wikipedia.org/wiki/Year_2038_problem – shadyabhi Jan 31 '12 at 05:29
  • 1
    @Hans: Wrong. `time_t` is 32-bit (`long`) on all existing 32-bit machines I know of, including in particular Linux/glibc. In any case, I think it's realistic to expect all 32-bit machines will be decommissioned by 2038... – R.. GitHub STOP HELPING ICE Jan 31 '12 at 05:38
  • 2
    @R.: Hopefully us greybeard C programmers will be able to command outrageously high hourly rates fixing the problem in about 2036 ;) – caf Jan 31 '12 at 09:17
  • @caf unfortunately we won't be able to do that anymore because [64-bit `time_t` support was added to Linux 5.1 and glibc 2.32](https://stackoverflow.com/q/14361651/995714) – phuclv Nov 28 '20 at 01:20
  • @R..GitHubSTOPHELPINGICE some embedded systems that starts their life from now may still spend their lifetime in the next few decades. And 32-bit embedded systems will always live just like how 8-bit microcontrollers still exist nowadays, because many applications don't need such a huge performant processor – phuclv Nov 28 '20 at 01:22
  • @phuclv: Yes, my prediction 8 years ago was rather inaccurate. – R.. GitHub STOP HELPING ICE Nov 28 '20 at 01:39

1 Answers1

10

LONG_MAX on a 64-bit machine is 2^63 - 1. Try this: go to http://google.com and enter 2^63 seconds in years. Look at the answer and decide whether you really need to worry about it.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • like like like. Yeah that's the funny thing about big number. I even thought, "oh maybe its just such a big number that we don't have to worry about it... nah 2^63 seconds is probably not THAT many years." I am satisfied with this answer. – Ziggy Jan 31 '12 at 05:42
  • 1
    I like the Wikipedia article on the issue. Using a signed 64-bit value introduces a new wraparound date at 15:30:08 on Sunday, 4 December 292,277,026,596. Will not be a problem for me at least. – r_ahlskog Jan 31 '12 at 07:53
  • 1
    Kind of makes me sad to think I may not be around to see this happen...in nearly 300 billion years from now. So puny. – Brenden Nov 06 '12 at 04:56
  • @Brenden Not with that attitude you won't. ;^) – rob mayoff Nov 06 '12 at 05:02
  • @r_ahlskog Oh dip! This will probably interfere with the planning of my birthday on December 7th, 292,277,026,596. Gotta make a note of that. – Williham Totland Mar 02 '16 at 19:30