> On Dec 19, 2025, at 12:31 PM, Paul Eggert <[email protected]> wrote:
> 
> On 2025-12-19 09:12, Christos Zoulas via tz wrote:
>> Gcc with -Wall -Wextra -Wtype-limits produces warnings with:
>> #define TYPE_SIGNED(T)  ((T)-1) < 0)
>> error: comparison of unsigned expression in '< 0' is always false 
>> [-Werror=type-limits]
>> Perhaps use something that checks the sign bit directly?
>> #define TYPE_SIGNED(T) \
>>     (((T)~(T)0 >> (sizeof(T) * CHAR_BIT - 1)) == (T)-1)
> 
> Let’s not, as the C standard does not require the more-complicated expression 
> to check the sign bit (e.g., there could be padding bits), whereas it does 
> require tzcode’s simpler expression to work (even on floating-point types).
> 
> More generally, GCC’s -Wtype-limits is not a good option for portable code, 
> since it’s too common for that flag to misfire on code intended to work 
> regardless of whether types like time_t are signed. This is why the 
> GCC_DEBUG_FLAGS in tzcode’s Makefile specifies -Wno-type-limits. There are 
> similar issues with GCC’s -Wformat-nonliteral and -Wsign-compare.
> 
> To check the code I suggest tzcode’s GCC_DEBUG_FLAGS, or if that’s too 
> drastic I suggest appending -Wno-format-nonliteral -Wno-sign-compare 
> -Wno-type-limits, as GCC_DEBUG_FLAGS does.

Ok.
> 
> PS. On my long list of things to do was to merge the changes between
> tzcode and NetBSD, so that tzcode’s localtime.c could be used unchanged in 
> NetBSD. It sounds like you’ve started the ball rolling on that; if I can be 
> of any help please let me know.

I have been reducing the changes between NetBSD and the official tzcode with 
each import. There are lot of gratuitous casting changes so that the 
localtime.c code can be compiled with both a 32 bit time_t and a 64 bit time_t 
so that it can provide compatibility for older APIs. I think I can change it so 
that the 32 bit time_t code just uses the 64 bit API instead and then most of 
the changes can go away.

Best,

christos

Attachment: signature.asc
Description: Message signed with OpenPGP

Reply via email to