I'm compiling a low level code using many bunch of bytes. In some case it is handy for me to define then using the double quote enclosed old C strings.
But when compiling with gcc or g++ (don't know behavior with other compilers), it keeps bothering me with sign of pointed string.
Basically when I write this
const unsigned char & refok = *"ABCDEFGHI";
EDIT: ok, the code above is not really working as it will in theory just keep a reference to a copy of the first char of the string. It actually allow access to all the string with some compilers because of optimization, but may break any time.
or this
const unsigned char oktoo[10] =
{'A','B','C','D','E','F','G','H','I',0};
the compiler doesn't say anything.
But it definitely reject this one:
const unsigned char * bad = "ABCDEFGHI";
with message
error: invalid conversion from
‘const char*’ to ‘const unsigned char*’
[-fpermissive]
It's not even a warning, it's an error.
I'm wondering why this one should be more of an issue than when using a reference, or converting individual chars from signed chars to unsigned chars ? Or am I missing something ?