Son Goku
No lover of dogma
- Joined
- 14 Jun 2004
- Messages
- 1,980
I seem to remember 1972, counting the number of seconds up, also not January 1, but some odd day...
Only thing, I don't have my compiler installed to check it again. This is the specific line of code we were using in a program I had to write for a C programming class:
On search online, it does suggest January 1970, (I'd have to double check with my compiler's internal documentation to see if this agrees, I seem to remember something dif printed in there), but on the dates something online suggests this:
http://pw1.netcom.com/~rogermw/Y2038.html
Only thing, I don't have my compiler installed to check it again. This is the specific line of code we were using in a program I had to write for a C programming class:
srand ( (unsigned) time ((time_t *) NULL)); /*Formula provided by user*/
On search online, it does suggest January 1970, (I'd have to double check with my compiler's internal documentation to see if this agrees, I seem to remember something dif printed in there), but on the dates something online suggests this:
http://pw1.netcom.com/~rogermw/Y2038.html
By the year 2038, the time_t representation for the current time will be over 2 140 000 000. And that's the problem. A modern 32-bit computer stores a "signed integer" data type, such as time_t, in 32 bits. The first of these bits is used for the positive/negative sign of the integer, while the remaining 31 bits are used to store the number itself. The highest number these 31 data bits can store works out to exactly 2 147 483 647. A time_t value of this exact number, 2 147 483 647, represents January 19, 2038, at 7 seconds past 3:14 AM Greenwich Mean Time. So, at 3:14:07 AM GMT on that fateful day, every time_t used in a 32-bit C or C++ program will reach its upper limit.
One second later, on 19-January-2038 at 3:14:08 AM GMT, disaster strikes.
Signed integers stored in a computer don't behave exactly like an automobile's odometer. When a 5-digit odometer reaches 99 999 miles, and then the driver goes one extra mile, the digits all "turn over" to 00000. But when a signed integer reaches its maximum value and then gets incremented, it wraps around to its lowest possible negative value. (The reasons for this have to do with a binary notation called "two's complement"; I won't bore you with the details here.) This means a 32-bit signed integer, such as a time_t, set to its maximum value of 2 147 483 647 and then incremented by 1, will become -2 147 483 648. Note that "-" sign at the beginning of this large number. A time_t value of -2 147 483 648 would represent December 13, 1901 at 8:45:52 PM GMT.