Warning: array alphabet initialized with string literal in brackets

In the template function, I currently have the following line:

static const unsigned char alphabet[17] = 
(Uppercase) ? ("0123456789ABCDEF") : ("0123456789abcdef");

Where Uppercaseis the template parameter. Using -pedanticgcc tells me:

warning: array 'alphabet' initialized by parenthesized string literal 
'("0123456789abcdef")'

How to get rid of this message (I want it to alphabetbe on the stack)?

+4
source share
2 answers

The easiest way to make your code uniquely valid is to use an array reference:

static const char (&alphabet)[17] = 
    (Uppercase) ? ("0123456789ABCDEF") : ("0123456789abcdef");

, . , neverhoodboy, , char, unsigned char.

, unsigned char, :

static const unsigned char uppercase[17] = "0123456789ABCDEF";
static const unsigned char lowercase[17] = "0123456789abcdef";
static const unsigned char (&alphabet)[17] =
    (Uppercase) ? uppercase : lowercase;

: Uppercase ( , , ), constexpr.

+3

("abc") - " 4 " l. ("abc") . - , .. - "...". char , const. , ("abc") char . , - ( , - const lvalue), char.

, alphabet . , , , .
EDIT. .

:

:

- , . , lvalue. , , , , , .

:

glvalues ​​ , , -, , .

:

A char ( char, char unsigned char), char16_t, char32_t wchar_t , char16_t , char32_t , , , . .

+1

All Articles