Issue
I have code:
static uint64_t password = 'password';
GCC say:
warning: character constant too long for its type static uint64_t password = 'password';
If I do so:
static uint64_t password = 'pass';
GCC say:
warning: multi-character character constant [-Wmultichar] static uint64_t password = 'pass';
That is, it turns out that sizeof(char) = 2, but is it not so, or is it not?
Solution
sizeof( char )
is guaranteed to be 1
, by definition.
C17§6.5.3.4¶4 When sizeof is applied to an operand that has type char, unsigned char, or signed char, (or a qualified version thereof) the result is 1. [...]
'...'
is an int
.
C17§6.4.4.4¶10 An integer character constant has type
int
. [...]
You apparently have a system where sizeof( int ) == 4
, which is why you could specify 4, but not 8 characters.
Note that it's really weird to use a multi-character constant.
And it's not portable.
C17§6.4.4.4¶10 [...] The value of an integer character constant containing more than one character (e.g.,
'ab'
), or containing a character or escape sequence that does not map to a single-byte execution character, is implementation-defined. [...]
Answered By - ikegami Answer Checked By - Gilberto Lyons (WPSolving Admin)