This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28335 compiler v6.2.9: argument of type "const S8 *" is incompatible with parameter of type "const char *"

Guru 19935 points

Hello,

My code typedefs unsigned int as a signed char, i.e.

typedef   signed char S8;

Why does the compiler (v6.2.9) produce an "argument of type "const S8 *" is incompatible with parameter of type "const char *" for the code snippet shown below?

strncpy((s8Name, (const S8 *) s8Data, 10);

According to page 92 of the compiler user's guide (spru514g), a signed char and a char should be equivalent data types.

Stephen

 


  • Are you compiling in C++ mode?  Are you using strict ANSI mode?

  • I am compiling c files and I am not using strict ANSI mode.

    The following compiler flags are used by my project:

    -v28 -ml -mt --float_support=fpu32 -Ooff --opt_for_speed=5  --diag_warning=225 --gen_func_subsections=on --asm_listing 

    Stephen

  • The C standard says that "signed char", "unsigned char", and plain "char" are three distinct types.  The type plain "char" has different semantics than "signed char", even for architectures where plain "char" has exactly the same representation as "signed char."  This is in contrast to plain "int", which is exactly "signed int".

    The notion of "compatible types" is a lot more strict in C that you'd expect; even though "signed char" and plain "char" have the same representation, they are not compatible because they are not the same type.

    When calling strncpy, since you're using a cast anyway, you should cast directly to the type that strncpy expects.

    You can safely ignore this warning in this case, but it will become an error if you use strict ANSI mode.