I'm trying to compile my code on a new system, and I'm suddenly running into trouble with one of my older libraries. This is an example snippet of the code that is causing the issue:
int main() {
static const unsigned char pad_block[8] = {
'\x80', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00'};
}
I'm compiling it using g++ -o test main.cpp
. My old system uses g++ 4.8.5, and there it compiles without issue - not even a warning. On the newer system with g++ 7.5.0, the following error appears:
main.cpp: In function ‘int main()’:
main.cpp:3:67: error: narrowing conversion of ‘'\37777777600'’ from ‘char’ to ‘unsigned char’ inside { } [-Wnarrowing]
'\x80', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00'};
I understand the issue of narrowing conversions in general, but this specific case I don't understand. My questions:
- Why does this issue suddenly appear, without specifying a new C++ version?
- Where does the number
'\37777777600'
come from? - I'd prefer not to change the library - is there another way around this?