Re: [hackers] [dwm][PATCH] Use proper conversion specifier and don't assume int == 32bits

From: Laslo Hunhold <dev_AT_frign.de>
Date: Wed, 16 Feb 2022 13:07:37 +0100

On Wed, 16 Feb 2022 17:46:47 +0600
NRK <nrk_AT_disroot.org> wrote:

Dear NRK,

> Attached two small patches, one fixing the conversion specifier to
> `%u` for unsigned int and another one not for not assuming int ==
> 32bits.
>
> These are more closer to pedantic cleanups rather than actual
> meaningful changes, but I noticed them while playing around on the
> codebase and thought I might send the patches anyways. Feel free to
> apply or reject them as you wish.

_AT_all: why not make a static compile-time-check on LENGTH(tags) and vary
the type accordingly?

#if LENGTH(tags) < 8
        typedef tag_bitmap uint_least8_t;
#elif LENGTH(tags) < 16
        typedef tag_bitmap uint_least16_t;
#elif LENGTH(tags) < 32
        typedef tag_bitmap uint_least32_t;
#elif LENGTH(tags) < 64
        typedef tag_bitmap uint_least64_t;
#else
        #error "tags-array too long"
#endif

The *_least-types and #error are all standard C99.

Accordingly you would have to redefine TAGMASK and change the type in
the Rule struct.

This catches the best of both worlds, I think: It will marginally
improve compile times, allow maximum standard-conformant bitmask-based
tag-count and gives a much clearer error message when the tags-array is
too long. Thoughts?

With best regards

Laslo
Received on Wed Feb 16 2022 - 13:07:37 CET

This archive was generated by hypermail 2.3.0 : Wed Feb 16 2022 - 13:12:38 CET