Is there an advantage to using unsigned long for timeval members?

I noticed that some programmers use unsigned long for tv_sec and tv_usec [when they copy them or work with them] from timeval, while they are defined as simply long.

Although this makes me wonder why they were defined so when time usually goes ahead.

+3
source share
3 answers

Usage long intfor these variables will work until the year 2038 , after which it tv_secwill overflow on machines where it longis 4 bytes.

timeval is defined as:

The <sys/time.h> header shall define the timeval structure that includes at least the following members:

time_t         tv_sec      Seconds. 
suseconds_t    tv_usec     Microseconds. 

, long time_t, 32- , 64- . , time_t, , 32- 64-.

unsigned long, 2100+ . time_t, , .

+4

unix, , , . , AT & T , 1960- .

, , 4 + unsigned. 0 .

+2

tv_sec time_t. tv_usec long , ( 50% ) tv_usec timeval , tv_sec. (POSIX) unsigned , , , , , .

, tv_usec , , , -999999 1999998 ( , / ).

+1
source

Source: https://habr.com/ru/post/1781102/


All Articles