Proposed asctime-related changes

Clive D.W. Feather clive at demon.net
Tue Aug 10 05:22:57 UTC 2004


Paul Eggert said:
> >     if ((unsigned) timeptr->tm_wday >= sizeof wday_name / sizeof wday_name[0])
> >
> > makes it one comparison instead of two.
> 
> Hold on a second.  Isn't this optimization invalid on hosts with
> padding bits where UINT_MAX == INT_MAX?  On such hosts,
> (unsigned)-INT_MAX is 1, which is in range, even though -INT_MAX isn't
> in range.

Doesn't matter for defensive coding. Okay, a value of -INT_MAX will print
as "Tue" rather than "???", but who cares?

Indeed, forget the test, add "???" to the end of the array, and just do:

    wday_name [timeptr->tm_wday & 7]

Similarly for the month, put 4 sets of ??? and go & 15.

-- 
Clive D.W. Feather  | Work:  <clive at demon.net>   | Tel:    +44 20 8495 6138
Internet Expert     | Home:  <clive at davros.org>  | Fax:    +44 870 051 9937
Demon Internet      | WWW: http://www.davros.org | Mobile: +44 7973 377646
Thus plc            |                            |



More information about the tz mailing list