On my system (4.13.11-1-ARCH, gcc 7.2.0) char is signed. When initializing an array of char with an integer literal like this:
const char mydata[] = {
0x80
};
I get the following error:
error: narrowing conversion of ‘128’ from ‘int’ to ‘char’ inside { } [-Wnarrowing]
However, when I instead do const char data = 0x80 the compiler is not worried of any narrowing, although it happens of course. The output is 7F, the highest positive signed char value.
Question
Why is the compiler not equally worried about truncation in both cases?