Subject: Re: time_t and fprintf()
To: Peter Galbavy <wonderland.org!peter@melb.werple.net.au>
From: John Birrell <cimaxp1!jb@werple.net.au>
List: port-alpha
Date: 07/10/1996 08:38:22
> 
> On an alpha time_t is defined as an int, and on i386 as a long (I believe
> on other platforms too). This causes me a problem when trying to compile
> clean code (well, gcc -Wall type clean).
> 
> If I want to print a time in seconds, using a time_t variable, then
> on the alpha it is a %u whilst on the other platforms a %lu. What
> is the "right thing" to do in these circumstances ? (There are a few
> hundred of these printf/fprintf calls, and adding casts to each seems
> a bit over the top :( )
> 
> BTW The man page for ctime(3) say in the first paragraph that the time
> in seconds is a long int...

"time_t" is defined by ANSI/ISO 9899-1990 (7.12.1) as an "arithmetic
type capable of representing times".

Not only does the standard *not* say how big time_t is, it doesn't even
say if it is signed or unsigned. And the definition of "arithmetic type"
includes floats too.

POSIX 1003.1b-1993 contains the rationale (B.4.5.1) that says:

"Implementations in which time_t is a 32-bit signed integer (most historical
implementations) will fail in the year 2038. This version of POSIX.1 does
not address this problem. However, the use of the new time_t type is
mandated in order to ease the eventual fix."

So, the "right thing" to do is to cast.

> 
> Regards,
> -- 
> Peter Galbavy                                           peter@wonderland.org
> @ Home                                                 phone://44/973/499465
> in Wonderland                              http://www.wonderland.org/~peter/
>                                snail://UK/NW1_6LE/London/21_Harewood_Avenue/
> 


-- 
John Birrell                                CIMlogic Pty Ltd
jb@cimlogic.com.au                          119 Cecil Street
Ph  +61  3 9690 6900                        South Melbourne Vic 3205
Fax +61  3 9690 6650                        Australia
Mob +61 18  353  137