On Mon, 3 Nov 2025 19:07:24 +0800
Kuan-Wei Chiu <[email protected]> wrote:

> +Cc David
> 
> Hi Guan-Chun,
> 
> If we need to respin this series, please Cc David when sending the next
> version.
> 
> On Mon, Nov 03, 2025 at 11:24:35AM +0100, Andy Shevchenko wrote:
...
> Hi David,
> 
> Since I believe many people test and care about W=1 builds, I think we
> need to find another way to avoid this warning? Perhaps we could
> consider what you suggested:
> 
> #define BASE64_REV_INIT(val_plus, val_comma, val_minus, val_slash, val_under) 
> { \
>       [ 0 ... '+'-1 ] = -1, \
>       [ '+' ] = val_plus, val_comma, val_minus, -1, val_slash, \
>       [ '0' ] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, \
>       [ '9'+1 ... 'A'-1 ] = -1, \
>       [ 'A' ] = 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, \
>                 23, 24, 25, 26, 27, 28, 28, 30, 31, 32, 33, 34, 35, \
>       [ 'Z'+1 ... '_'-1 ] = -1, \
>       [ '_' ] = val_under, \
>       [ '_'+1 ... 'a'-1 ] = -1, \
>       [ 'a' ] = 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, \
>                 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, \
>       [ 'z'+1 ... 255 ] = -1 \
> }

I've a slightly better version:

#define INIT_62_63(ch, ch_62, ch_63) \
        [ ch ] = ch == ch_62 ? 62 : ch == ch_63 ? 63 : -1

#define BASE64_REV_INIT(ch_62, ch_63) { \
        [ 0 ... '0' - 6 ] = -1, \
        INIT_62_63('+', ch_62, ch_63), \
        INIT_62_63(',', ch_62, ch_63), \
        INIT_62_63('-', ch_62, ch_63), \
        INIT_62_63('.', ch_62, ch_63), \
        INIT_62_63('/', ch_62, ch_63), \
        [ '0' ] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, \
        [ '9' + 1 ... 'A' - 1 ] = -1, \
        [ 'A' ] = 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, \
                  23, 24, 25, 26, 27, 28, 28, 30, 31, 32, 33, 34, 35, \
        [ 'Z' + 1 ... '_' - 1 ] = -1, \
        INIT_62_63('_', ch_62, ch_63), \
        [ '_' + 1 ... 'a' - 1 ] = -1, \
        [ 'a' ] = 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, \
                  49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, \
        [ 'z' + 1 ... 255 ] = -1 \
}

that only requires that INIT_62_63() be used for all the characters
that are used for 62 and 63 - it can be used for extra ones (eg '.').
If some code wants to use different characters; the -1 need replacing
with INIT_62_63() but nothing else has to be changed.

I used '0' - 6 (rather than '+' - 1 - or any other expression for 0x2a)
to (possibly) make the table obviously correct without referring to the
ascii code table.

        David




Reply via email to