Paul Eggert <[email protected]> writes:

> On 2026-03-07 15:09, Collin Funk wrote:
>
>> +# if ! defined __gl_stdc_rotate_left
>
> The existing style in that file is to prefer #ifdef and #ifndef to the
> longer wording. (Call me a traditionalist....) Here and elsewhere.

Sure, I can change those.

>> +#  define __gl_stdc_rotate_left(value, count)             \
>> +  ((value << (count & (sizeof value * 8 - 1)))            \
>> +   | (value >> ((-count) & (sizeof value * 8 - 1))))
>> +# endif
>
> 8 * sizeof (something) is easier to read than sizeof (something) * 8.
> To avoid glitches after possible later modifications, should
> parenthesize args when used. No need for those parens in (-count).
> E.g.:
>
>   #  define __gl_stdc_rotate_left(v, c) \
>     (((v) << ((c) & (8 * sizeof (v) - 1))) \
>      | ((v) >> (-(c) & (8 * sizeof (v) - 1))))
>
> Similarly for __gl_stdc_rotate_right.

Likewise.

I'll probably keep the multiplication order since Bruno and I are more
used to it. My impression is that the other changes are more important
to you, though.

>> +#  define stdc_rotate_left(value, count)                                \
>> +  (_GL_STDBIT_TYPEOF_CAST                                               \
>> +   (value,                                                              \
>> +    (sizeof (value) == 1 ? stdc_rotate_left_uc (value, count)           \
>> +     : (sizeof (value) == sizeof (unsigned short int)                   \
>> +        ? stdc_rotate_left_us (value, count)                            \
>> +        : (sizeof (value) == sizeof 0u                                  \
>> +           ? stdc_rotate_left_ui (value, count)                         \
>> +           : (sizeof (value) == sizeof 0ul                              \
>> +              ? stdc_rotate_left_ul (value, count)                      \
>> +              : stdc_rotate_left_ull (value, count)))))))
>
> The staggered indenting is a bit hard to read. Could we redo this in
> the existing style (e.g. stdbit_bit_ceil) by using shorter arg names
> v, c? That should be easier to read.

Sure. I find nested ternary conditionals hard to read regardless of how
they are written. So I do not have strong style preferences for them.

Collin

Reply via email to