The following line of code produces a compiler warning with HP-UX's C++ compiler:
strcpy(var, "string")
Output:
error #2167: argument of type "unsigned char *"
is incompatible with parameter of type "char *"
Please note: var
is the unsigned char *
here - its data type is outside of my control.
Two questions:
- What does incompatibility mean in the context of these two types? What would happen if the compiler was forced to accept the conversion? An example would be appreciated.
- What would be a safe way to make the above line of code work, assuming I have to use
strcpy
?
char
,signed char
andunsigned char
are distinct types. You can't use anunsigned char *
where achar *
is expected, and vice versa, without using type casts. But why are you passing anunsigned char *
to achar *
based API to begin with? What kind of data does theunsigned char *
point to? You might consider usingmemcpy()
instead. – Poltroonvar
. It would also be helpful to include the version of HP-UX and/or the compiler you're using. – Bertberta