I am writing a unit test checking some binary data against an expected array. The expected array in question is just some series of bytes, doesn't matter specifically:
char expected[] = {0x42, 0xde, 0xad, 0xbe, 0xef};
This compiled fine in C++, but with C++11 this issues a warning on narrowing conversion. I compile with -Werror
because warnings matter, so that line does not compile for me. As far as I'm aware, there's no literal suffix for char, so it seems I'd have to do:
char expected[] = {static_cast<char>(0x42), static_cast<char>(0xde), ... };
That seems pretty unwieldy to me. Is there a better way to construct this character array? (Outside of either removing -Werror
or adding -Wno-narrowing
).
unsigned char
oruint8_t
. – Shakerunsigned char
oruint8_t
as specified before for variables meant to hold byte values. – Liable