int8_t* and char*

假装没事ソ 提交于 2019-12-10 20:43:32

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!