Why is a signed integer used to represent timestamps? There is a clearly defined start at 1970 that’s represented as 0, so why would we need numbers before that? Are negative timestamps used anywhere?
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Early versions of C didn’t have unsigned integers. (Some programmers used pointers when they needed unsigned arithmetic.) I don’t know which came first, the
time() function or unsigned types, but I suspect the representation was established before unsigned types were universally available. And 2038 was far enough in the future that it probably wasn’t worth worrying about. I doubt that many people thought Unix would still exist by then.
Another advantage of a signed
time_t is that extending it to 64 bits (which is already happening on some systems) lets you represent times several hundred billion years into the future without losing the ability to represent times before 1970. (That’s why I oppose switching to a 32-bit unsigned
time_t; we have enough time to transition to 64 bits.)
It’s to support timestamps and dates before January 1st, 1970.