Proposed changes to asctime.c, zdump.c, and localtime.c
Paul Eggert
eggert at CS.UCLA.EDU
Tue Dec 28 20:12:06 UTC 2004
"Olson, Arthur David (NIH/NCI)" <olsona at dc37a.nci.nih.gov> writes:
> + static char *
> + tformat()
> + {
> + if (0.5 == (time_t) 0.5) /* floating */
> + return "%g";
This mishandles the case where time_t is long double; in that case,
presumably you'd use the format "%Lg".
Also (and this is a problem with the int code of tformat as well),
there's no guarantee that long double has a size greater than double.
You might want to put in a comment here, that says the code assumes
three things: (1) that arithmetic types with larger size are no
narrower than types with smaller size, (2) if two types s and t are
the same width, then it's OK to use s's format on a value of type t (a
common case is int and long int both being 32 bits wide), and (3) that
time_t must be either narrower than int, or the same width as either
int, long int, or long long int. C99 does not guarantee any of these
assumptions.
If you want to remove these assumptions, then we could go down that
road, but the basic idea will be to implement that part of C99 that's
needed (e.g., intmax_t, uintmax_t).
> + if (sizeof (time_t) == sizeof (long))
> + return "%ld";
This should be "if (sizeof (time_t) > sizeof (int))", for consistency
with the other tests (and also to avoid storing the unnecessary "l"
:-). Similarly for the unsigned code.
More information about the tz
mailing list