Re: [hackers] [dwm][PATCH] Use proper conversion specifier and don't assume int == 32bits
On Thu, 17 Feb 2022 01:33:40 +0100 Hiltjo Posthuma wrote: > This is crazy, keep it simple As you know, madness is like gravity ... all it takes is a little (git) push.
Re: [hackers] [dwm][PATCH] Use proper conversion specifier and don't assume int == 32bits
On Wed, Feb 16, 2022 at 01:07:37PM +0100, Laslo Hunhold wrote: > On Wed, 16 Feb 2022 17:46:47 +0600 > NRK 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. > > @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
Re: [hackers] [dwm][PATCH] Use proper conversion specifier and don't assume int == 32bits
On Wed, 16 Feb 2022 19:10:06 +0600 NRK wrote: Dear NRK, > I don't think this is possible, at least not with the LENGTH macro. > The pre-processor doesn't have access to `sizeof` operator. thanks for your quick and helpful answer, and sorry on my behalf for this mistake. It totally makes sense that the preprocessor does not have access to sizeof of course, given it would have to build an AST to elaborate the size of the constant array. With best regards Laslo
Re: [hackers] [dwm][PATCH] Use proper conversion specifier and don't assume int == 32bits
On Wed, Feb 16, 2022 at 01:07:37PM +0100, Laslo Hunhold wrote: > @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 Hi Laslo, I don't think this is possible, at least not with the LENGTH macro. The pre-processor doesn't have access to `sizeof` operator. - NRK
Re: [hackers] [dwm][PATCH] Use proper conversion specifier and don't assume int == 32bits
On Wed, 16 Feb 2022 17:46:47 +0600 NRK 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. @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