On 5/23/24 12:38, Ian Abbott wrote:
On 23/05/2024 07:41, Erwin Rol wrote:

The following code;

auto t = std::chrono::system_clock::now();

does not seem to work correctly. When the system date is less than 2038 it works and gives back the correct time, but for dates > 2038 it seems to return some 1970 date.

I guess that libstdc++ in the toolchain would need to be rebuilt with 64-bit time_t support.  Although <chrono> uses a 64-bit integer type internally, some of the functions such as std::chrono::system_clock::now() use compiled in code that picks up the C system time ABI at the time libstdc++ was built.  So now() will read the system time using the 32-bit system time ABI (so will suffer from Y2038 problems) and convert it to its own internal 64-bit integer type. Other functions such as std::chrono::system_clock::from_time_t(std::time_t) are not compiled in so will use whatever C system time ABI was selected when <chrono> was included.

I believe libstd++ uses gettimeofday internally, which should use time_t for the seconds field, which should be 64bit if _TIME_BITS=64 is defined. I just hacked the Toolchain to try it, but it is a slow process, build toolchain -> build project -> test :-)

If I figure it out I'll let you guys know (so it can be added to the official Toolchain)

- Erwin

Reply via email to