问题
Why does the statement const int8_t* cstr = "asdf";
gives error
invalid conversion from ‘const char*’ to ‘const int8_t*’
Aren't int8_t*
and char*
same?
Am I missing some subtle thing here?!
回答1:
const signed char*
is not the same as const char*
. Check your compilation settings, because that would explain it. int8_t
is always (never say never =) at least everywhere i've seen) defined as signed char
.
回答2:
According to [18.4 Integer types]:
typedef signed integer type int8_t; // optional
And [3.9.1 Fundamental types]:
Plain char, signed char, and unsigned char are three distinct types
int8_t
is a signed integer type (on my system defined as signed char
) and char
and signed char
are distinct types, so they are different.
来源:https://stackoverflow.com/questions/12381855/int8-t-and-char