seasoned_geek
2017-02-12 00:53:00 UTC
All,
While working on a new book today I tried the following test program on Linux Lite 3.2 64-bit.
// max_time_test.cpp
#include <limits>
#include <iostream>
#include <time.h>
#include <string.h>
#include <stdio.h>
int main()
{
time_t maxTime = 0;
std::cout << "maxTime is " << maxTime << std::endl;
printf( "maxTime %s\n", ctime(&maxTime));
printf( "asctime() %s\n", asctime(gmtime(&maxTime)));
printf( "Year: %d\n", gmtime(&maxTime)->tm_year+1900);
maxTime = std::numeric_limits<time_t>::max();
std::cout << "maxTime is " << maxTime << std::endl;
printf( "\nmaxTime %s\n", ctime(&maxTime));
printf( "asctime() %s\n", asctime(gmtime(&maxTime)));
printf( "Year: %d\n", gmtime(&maxTime)->tm_year+1900);
return 0;
}
***@roland-HP-Compaq-8100-Elite-SFF-PC:~/tst$ g++ max_time_test.cpp
***@roland-HP-Compaq-8100-Elite-SFF-PC:~/tst$ ./max_time_test
maxTime is 0
maxTime Wed Dec 31 18:00:00 1969
asctime() Thu Jan 1 00:00:00 1970
Year: 1970
maxTime is 9223372036854775807
maxTime (null)
asctime() (null)
Segmentation fault
Just for grins I fired up my trusty DS-10 running hobbyist license and OpenVMS 8.3 (yeppers, I'm a loooong way from current on that box.) I had to tweak the code slightly because standards have moved on over the last decade.
$ type max_time_test.cpp
// max_time_test.cpp
#include <limits>
#include <iostream>
#include <time.h>
#include <string.h>
#include <stdio.h>
int main()
{
time_t maxTime = 0;
cout << "maxTime is " << maxTime << endl;
printf( "maxTime %s\n", ctime(&maxTime));
printf( "asctime() %s\n", asctime(gmtime(&maxTime)));
printf( "Year: %d\n", gmtime(&maxTime)->tm_year+1900)
;
maxTime = std::numeric_limits<time_t>::max();
cout << "maxTime is " << maxTime << endl;
printf( "\nmaxTime %s\n", ctime(&maxTime));
printf( "asctime() %s\n", asctime(gmtime(&maxTime)));
printf( "Year: %d\n", gmtime(&maxTime)->tm_year+1900)
;
return 0;
}
$
$ cxx max_time_test.cpp
$ cxxlink max_time_test
$ run max_time_test
maxTime is 0
maxTime Wed Dec 31 18:00:00 1969
asctime() Thu Jan 1 00:00:00 1970
Year: 1970
maxTime is 4294967295
maxTime Sun Feb 7 00:28:15 2106
asctime() Sun Feb 7 06:28:15 2106
Year: 2106
$
10 years out of date and OpenVMS is still well ahead of that GNU stuff!
Since Linux Lite is a YABU (Yet Another uBUntu) this "feature" is in a rash of Linux distros having different names. It also means that many embedded systems being built and shipped today have this debacle lying in wait. If they have data entry screens using std::numeric_limits<time_t>::max(); to obtain a value for date validation it will first show up there. I didn't run detailed tests to see if the current GNU stuff fails one second after 3:14:08 AM (GMT) on January 19, 2038, but seriously, these toys aren't ready for prime time.
Personally I wonder just how long this time bomb has been in place? I also wonder just how many embedded control systems in factories, nuke plants, mills and other has-to-always-work places have this bomb ticking away. Given how long nuke plants tend to be in operation, I fret much over such things.
http://news.nationalgeographic.com/news/energy/2011/07/pictures/110720-10-oldest-nuclear-plants-in-the-us/
Was kind of shocked to learn about Oyster built in 1969 and still in operation. I _thought_ everything prior to 1980 had been decommissioned.
At any rate, passing this tidbit along to you all in case you are using GNU somewhere.
While working on a new book today I tried the following test program on Linux Lite 3.2 64-bit.
// max_time_test.cpp
#include <limits>
#include <iostream>
#include <time.h>
#include <string.h>
#include <stdio.h>
int main()
{
time_t maxTime = 0;
std::cout << "maxTime is " << maxTime << std::endl;
printf( "maxTime %s\n", ctime(&maxTime));
printf( "asctime() %s\n", asctime(gmtime(&maxTime)));
printf( "Year: %d\n", gmtime(&maxTime)->tm_year+1900);
maxTime = std::numeric_limits<time_t>::max();
std::cout << "maxTime is " << maxTime << std::endl;
printf( "\nmaxTime %s\n", ctime(&maxTime));
printf( "asctime() %s\n", asctime(gmtime(&maxTime)));
printf( "Year: %d\n", gmtime(&maxTime)->tm_year+1900);
return 0;
}
***@roland-HP-Compaq-8100-Elite-SFF-PC:~/tst$ g++ max_time_test.cpp
***@roland-HP-Compaq-8100-Elite-SFF-PC:~/tst$ ./max_time_test
maxTime is 0
maxTime Wed Dec 31 18:00:00 1969
asctime() Thu Jan 1 00:00:00 1970
Year: 1970
maxTime is 9223372036854775807
maxTime (null)
asctime() (null)
Segmentation fault
Just for grins I fired up my trusty DS-10 running hobbyist license and OpenVMS 8.3 (yeppers, I'm a loooong way from current on that box.) I had to tweak the code slightly because standards have moved on over the last decade.
$ type max_time_test.cpp
// max_time_test.cpp
#include <limits>
#include <iostream>
#include <time.h>
#include <string.h>
#include <stdio.h>
int main()
{
time_t maxTime = 0;
cout << "maxTime is " << maxTime << endl;
printf( "maxTime %s\n", ctime(&maxTime));
printf( "asctime() %s\n", asctime(gmtime(&maxTime)));
printf( "Year: %d\n", gmtime(&maxTime)->tm_year+1900)
;
maxTime = std::numeric_limits<time_t>::max();
cout << "maxTime is " << maxTime << endl;
printf( "\nmaxTime %s\n", ctime(&maxTime));
printf( "asctime() %s\n", asctime(gmtime(&maxTime)));
printf( "Year: %d\n", gmtime(&maxTime)->tm_year+1900)
;
return 0;
}
$
$ cxx max_time_test.cpp
$ cxxlink max_time_test
$ run max_time_test
maxTime is 0
maxTime Wed Dec 31 18:00:00 1969
asctime() Thu Jan 1 00:00:00 1970
Year: 1970
maxTime is 4294967295
maxTime Sun Feb 7 00:28:15 2106
asctime() Sun Feb 7 06:28:15 2106
Year: 2106
$
10 years out of date and OpenVMS is still well ahead of that GNU stuff!
Since Linux Lite is a YABU (Yet Another uBUntu) this "feature" is in a rash of Linux distros having different names. It also means that many embedded systems being built and shipped today have this debacle lying in wait. If they have data entry screens using std::numeric_limits<time_t>::max(); to obtain a value for date validation it will first show up there. I didn't run detailed tests to see if the current GNU stuff fails one second after 3:14:08 AM (GMT) on January 19, 2038, but seriously, these toys aren't ready for prime time.
Personally I wonder just how long this time bomb has been in place? I also wonder just how many embedded control systems in factories, nuke plants, mills and other has-to-always-work places have this bomb ticking away. Given how long nuke plants tend to be in operation, I fret much over such things.
http://news.nationalgeographic.com/news/energy/2011/07/pictures/110720-10-oldest-nuclear-plants-in-the-us/
Was kind of shocked to learn about Oyster built in 1969 and still in operation. I _thought_ everything prior to 1980 had been decommissioned.
At any rate, passing this tidbit along to you all in case you are using GNU somewhere.