Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Jun 2001 12:57:58 -0400
From:      Garance A Drosihn <drosih@rpi.edu>
To:        Poul-Henning Kamp <phk@critter.freebsd.dk>, Peter Wemm <peter@wemm.org>
Cc:        John Polstra <jdp@polstra.com>, arch@FreeBSD.ORG
Subject:   Re: time_t definition is wrong
Message-ID:  <p05100e0fb74019e19da6@[128.113.24.47]>
In-Reply-To: <45913.991557175@critter>
References:  <45913.991557175@critter>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?p05100e0fb74019e19da6>