I am not able to use int8_t*
type inside the strlen()
function, it gives error like
invalid conversion from int8_t* to const char*`
Please help me, how to resolve this issue?
If I change the type from int8_t*
to char*
then it is working fine, but I can't use char*
as per my project coding guidelines I have to use either int8_t
or uint8_t
, so please help me to resolve this issue.
The "solution" to this is one of three things:
char
instead of int8_t
. strlen
type function. int8_t
to char
at the callsite. The cast solution would look something like this:
int8_t something[100];
... something gets set somehow ...
size_t len = strlen((char *)something);
or in C++:
size_t len = strlen(static_cast<char *>(something));
Personally, I think option 1 is the "right" one if the data being processed is really string data. That is what the char
type is for, but not what int8_t
is for.
Don't use int8_t
unless it meets your requirements. It is not a synonym for char
. It is a signed integral type that has exactly 8 bits, and it won't exist on platforms that don't have 8-bit integral types. When you want to deal with char
objects, use the type char
. That's what it's for.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.