question

HaraldRenFlasch-4704 avatar image
0 Votes"
HaraldRenFlasch-4704 asked HaraldRenFlasch-4704 edited

struct timeval (winsock2.h) - Y2K38

I wondering that timeval struct still using long (32bit) members causing the Y2K38 issue...

Is there a plan to make that Y2K38 compatible or should I use alternatives to the timeval struct and why is this not marked as deprecated in winsock2.h?

I guess it is not that easy just changing the long to __int64...

Exists there a way to check/verify C/C++ source code if it is Y2K38 compatible or not? Clang does not offer such thing?

Is it just timeval or are there others? E.g. time_t (Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h) and tm (Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_wtime.h) already having solutions.


c++
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Time_t type represents the number of seconds elapsed since midnight, January 1, 1970. But , the timeval structure is used to specify a time interval. ​ You don't need to worry about the problem because each data structure has its limits.

1 Vote 1 ·

Thanks for the answer!

For some reason we used timeval from winsock2.h and not from sys/time.h ... but the problem is a bit more complex, specially when writing code that it is used under Windows and Linux ...

There is also a timespec:
https://en.cppreference.com/w/c/chrono/timespec

A bit confusing...

Windows:
timeval -- winsock2.h -- used for time interval

Linux:
timeval -- sys/time.h -- used for date/time(?)

Both:
timespec -- time.h -- Structure holding an interval broken down into seconds and nanoseconds.

... so, when need to deal with Date/Time (not interval!) it's better using struct tm or struct time_t ...


EDIT_2021-09-13 16:14: struct tm and time_t was also no option since in my case needing precision at least for micro seconds + for time_t there existed no gSOAP converter... so my solution is, using timeval under Linux and under Windows own (64bit-)definition of "timeval" ...

Still interesting that the data type "timeval" is so different in Windows and Linux. In the past it was no problem, but when needing to be "Y2K23 fit" on Windows and Linux platform...

0 Votes 0 ·

0 Answers