[tz] Dubious coding in tzcode 2019b

John Haxby john.haxby at oracle.com
Fri Jul 19 17:51:08 UTC 2019

> On 19 Jul 2019, at 17:33, Paul Eggert <eggert at cs.ucla.edu> wrote:
>> I think I would write it as:
>>     thistimecnt = - (ptrdiff_t) (locut + hicut);
>> because that shows the intent better.
> I would rather avoid unnecessary casts, so the attached proposed patch does it the way you suggest except without the cast. This should make the source code a bit clearer, and maybe it will pacify the Microsoft compiler.
> I'm not worried about the style issue of treating true and false as 1 and 0, as the idiom should be reasonably obvious to readers who know C. (Anybody who's been around long enough to remember C's predecessor BCPL where true was all-bits-1, should know by now that C does things differently. :-) So if the Microsoft compiler warns even with the patch, I'm somewhat inclined to suggest that people just ignore these bogus warnings, or use a compiler flag that shuts them off.

You'll see "x = !!foo" quite often in the Linux kernel which converts any non-zero integer to "1".   It certainly makes it crystal clear that x is 0 or 1.

As an aside, C's lack of a strong boolean type has caused all kinds of problems down the years.


More information about the tz mailing list