From owner-freebsd-arch Sun Jun 3 9:58:24 2001 Delivered-To: freebsd-arch@freebsd.org Received: from mail.rpi.edu (mail.rpi.edu [128.113.22.40]) by hub.freebsd.org (Postfix) with ESMTP id 9480837B405 for ; Sun, 3 Jun 2001 09:58:21 -0700 (PDT) (envelope-from drosih@rpi.edu) Received: from [128.113.24.47] (gilead.acs.rpi.edu [128.113.24.47]) by mail.rpi.edu (8.11.3/8.11.3) with ESMTP id f53Gw0S34968; Sun, 3 Jun 2001 12:58:00 -0400 Mime-Version: 1.0 X-Sender: drosih@mail.rpi.edu Message-Id: In-Reply-To: <45913.991557175@critter> References: <45913.991557175@critter> Date: Sun, 3 Jun 2001 12:57:58 -0400 To: Poul-Henning Kamp , Peter Wemm From: Garance A Drosihn Subject: Re: time_t definition is wrong Cc: John Polstra , arch@FreeBSD.ORG Content-Type: text/plain; charset="us-ascii" ; format="flowed" Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG At 10:32 AM +0200 6/3/01, Poul-Henning Kamp wrote: >Most of the trouble here is printf. What we need is to be able >to say something like > > printf("time= %{time_t}\n", time_second); The following is what Garrett noted in this thread in -stable. I'm not sure where this leaves us, other than it shows that no matter what type we pick for type_t, there will still be some portability problems, at least when it comes to printing. It looks like the best way to solve the printing-issue is to always use strftime(). - Garance - - - - At 8:33 PM -0400 6/2/01, Garrett Wollman wrote: > The pw->pw_chage and pw->pw_passwd are of time_t. But, > in the above, %ld is used for them. This is a general problem; there is no portable way to print a time_t that does not include the following steps: 1) Determine whether time_t is integral, floating-point, or (new in C99) complex. 2) If time_t is integral, determine whether it is signed or unsigned. 3) If the compilation environment is not C99, and time_t is integral, cast to (appropriately signed) long and print with %ld or %lu as appropriate. If the compilation environment is (close enough to) C99, cast to (appropriately signed) intmax_t and print with %jd or %ju as appropriate. If time_t is floating-point, cast to long double and print with %Lf. If time_t is complex, you have a lot more serious problems to deal with. There is a simple way around this, for POSIX systems only: use strftime() with the %s format. -GAWollman - - - - To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message