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

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Thu, 17 Feb 2022 01:33:40 +0100

On Wed, Feb 16, 2022 at 01:07:37PM +0100, Laslo Hunhold wrote:
> 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
>

This is crazy, keep it simple

-- 
Kind regards,
Hiltjo
Received on Thu Feb 17 2022 - 01:33:40 CET

This archive was generated by hypermail 2.3.0 : Thu Feb 17 2022 - 01:36:36 CET