Subject: Re: time_t and fprintf()
To: Peter Galbavy <peter@wonderland.org>
From: Chris G Demetriou <Chris_G_Demetriou@ux2.sp.cs.cmu.edu>
List: port-alpha
Date: 07/09/1996 17:35:05
> 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 :( )

Adding casts is the best you're going to do, unfortunately.  I'd
suggest casting to 'int' and printing as 'int', as long as the
platforms you're running on have at least 32-bit integers.

For NetBSD/Alpha, I took the cue from Digital UNIX (___FORMERLY DEC
OSF/1___ 8-).  It also typedef's time_t as an int.


This is a well-known and very annoying problem with the existing
definition of printf format specifiers.  I dunno what, if anything,
the standard C committee is planning to do about it, but it's a
gigantic lose the way it is now.


> BTW The man page for ctime(3) say in the first paragraph that the time
> in seconds is a long int...

No doubt; that's the way a typical type-size-naive (or out of date 8-)
manual page would describe it.  Way back when, when UNIX was running
on a PDP-11, e.g. when 'time()' came into being, that made sense...

However, it's not representative of present reality.



cgd