I have a method that takes unsigned chars, but I want to pass it 0x01.
I know I can represent hex chars in strings by going “\x01″…
but that is still a signed char.
EDIT:
some code:
kennys_hash((unsigned char const *)"\x00"); // the method call
the error:
src/main.cpp:88: error: invalid conversion from ‘const unsigned char*’ to ‘unsigned char’
src/main.cpp:88: error: initializing argument 1 of ‘unsigned char kennys_hash(unsigned char)’
the method header:
unsigned char kennys_hash(unsigned char out)
ALso, when the cast is just to unsigned char, I get this error:
src/main.cpp:88: error: cast from ‘const char*’ to ‘unsigned char’ loses precision
0x01is the same as1, which is positive, and thus it doesn’t matter if it’s considered to be signed or unsigned, the value is the same.If you want to have an unsigned type on the literal, use
0x01u.