Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

int8_t* and char*

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?!

like image 882
zeropoint Avatar asked Dec 05 '25 08:12

zeropoint


2 Answers

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.

like image 174
WhozCraig Avatar answered Dec 07 '25 22:12

WhozCraig


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.

like image 24
Jesse Good Avatar answered Dec 07 '25 21:12

Jesse Good



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!