asctime.c
Paul Eggert
eggert at CS.UCLA.EDU
Tue Jul 27 20:59:16 UTC 2004
Robert Elz <kre at munnari.oz.au> writes:
> %4ld doesn't print a leading 0, did you actually test that?
Sorry, no, I misread the format. But leading spaces aren't allowed by
the standard, so an implementation can't use %4ld either.
> If the standard actually says what you say (I don't have anything to
> do with it) then the standard is broken, and someone should file a
> defect report.
Feel free, but when I suggested something like that earlier this year
<http://groups.google.com/groups?selm=7wekp4gm9s.fsf%40sic.twinsun.com>,
the response from P. J. Plauger (a member of the standardization
committee) was that it was not important enough to spend energy on.
See
<http://groups.google.com/groups?q=g:thl4051128685d&selm=fIhvc.24831%24oh7.21793%40nwrddc01.gnilink.net>.
> This one isn't just of academic interest, there's lots of code that
> does stuff like
>
> printf("The date is: %.24s today\n", asctime(tm));
>
> and expects that there cannot be a newline between the date and the
> word "today".
Yup, it's a problem all right. However, in my experience code like
that is generally nonportable already, since it assumes that asctime
can't possibly overrun its static buffer, and this assumption is false
for many POSIX platforms. So I don't think supporting this code is
important enough to violate the standard.
Also, more typically I see code like this:
printf("The date is: %.24s today\n", ctime(&t));
and this is definitely broken for arbitrary time_t values, since ctime
returns NULL if the time_t is so large that tm_year cannot represent
the year.
More information about the tz
mailing list