asctime.c

Paul Eggert eggert at CS.UCLA.EDU
Tue Jul 27 19:13:14 UTC 2004


Robert Elz <kre at munnari.oz.au> writes:

> The \n should be in buf[25] and absolutely nowhere else (for correct
> historical compatibility).

Here (as with the %4ld issue) we have a disagreement between Unix
Version 7 and the C standard.  V7 asctime always generated 26 bytes of
output (including the terminating null), and always generated 4 bytes
for the year, no matter what.  It also generated only positive
numbers, even when (say) tm_sec was -1.  But the C standard says that
sometimes fewer bytes of output must be generated (in particular, if
the year is in the range -99 through 999), and that a negative number
must be printed in some cases (e.g., when tm_sec is -1).

I'd prefer to conform to the current standard when it disagrees with
tradition, particularly when these are cases that don't really matter
for practical programs (only standards nerds like us will care about
them :-).


> The most postable format is %02.2d

Yes, I suppose this is the most portable to ancient hosts, but
unfortunately GCC complains about it:

   warning: `0' flag ignored with precision and `%d' printf format

(I'm using GCC 3.4.1.)  But this doesn't prevent compilation from
succeeding, so I guess it's OK.



More information about the tz mailing list