FW: Strftime's %C and %y formats versus wide-ranging tm_year valu es

Paul Eggert eggert at CS.UCLA.EDU
Tue Sep 28 17:43:52 UTC 2004

"Olson, Arthur David (NIH/NCI)" <olsona at dc37a.nci.nih.gov> writes:

> Of course it's possibly to simply...
> 	typedef long long		raw_year_type;
> ...and use the defined type for year-holding variables to avoid problems
> with really big tm_year values.

These suggestions don't work in general.  First, "long long" is not
required by either C89 or K&R, and many older platforms don't have it.
Second, C99 does not require "long long" to be wider than "int", and
using "long long" doesn't solve overflow problems on those (admittedly
rare) hosts where int == long == long long.

The first point is probably more important as a practical matter, but
as the code does attempt to be portable to all standard environments
the second point is still of some concern.

Overall, the proposed patch isn't all that bad in the code-complexity
department.  The overflow fixes themselves adds only 9 lines total to
strftime.c and tzfile.h.  (The proposed patch also includes 8 lines of
%Y, %C, and %y commentary that is independent of the overflow fixes,
but this can be omitted if you like.)

More information about the tz mailing list