On Mon, 05 Oct 2020 15:16:24 -0000, Roderick wrote:

> The result of time() has type time_t and we know what kind of number
> goes there: seconds since 0 hours, 0 minutes, 0 seconds, January 1,
> 1970, Coordinated Universal Time.

32-bit time_t rolls over at 03:14:07 on Tuesday, 19 January 2038.

> In my FreeBSD running on a 64 bit processor this type is: int (__32_t).
> It considers this size enough for above information.

Are you sure about that?  FreeBSD declares __time_t to be __int64_t
on amd64.  On FreeBSD/amd64 __int64_t is defined as a long.

> In my OpenBSD running on a 32 bit processor this type is: long long
> (__64_t).

Correct.  OpenBSD uses long long for int64_t on all architectures
for consistency.  Other OSes use long for int64_t on 64-bit systems.

> None of both has an unsigned type, although time moves forward
> (more or less fast!!!).

time_t must be signed in order to represent times in the past.

> Is there a reason for this discrepancy? Is there no standard for the
> size of time_t?

The POSIX standard does not really specify the size of time_t.  Most
(all?) 64-bit system use a 64-bit time_t.  Some 32-bit systems use
a 64-bit time_t too, in order to support times after 2038.  OpenBSD
is one of them.

> And what does mean the types with __? I find it so confusing. :)

It is to avoid namespace pollution.  The underlying types need to
be visible to other header files but unless you pull in the
specific header file they are not visible in the main namespace.

You can't really print a time_t via printf(3) without a cast.  On
OpenBSD we generally print it with %lld and cast the argument to
long long.

 - todd

Reply via email to