I have a program like this,
void test(char* a)
{
printf("%s",a); // Trying to print the function name "add" here
return;
}
int add(int,int)
{
test(__FUNCTION__); // I need the function name add to be passed to the test function
...................
....................
}
But while building I am getting the error in a C compiler(gcc flavour) like this,
passing argument 1 of ‘test’ discards qualifiers from pointer target type
Please have a look at this,
/R
From here:
So, you’re trying to pass a
const char *to achar *, discarding theconstqualifier. Since in yourtestfunction you aren’t modifying the passed string, change its parameter type toconst char *, promising to the caller that you aren’t modifying its string.By the way, to get
constcorrectness right you should always remember to declare pointers asconstif they are "input-only" parameters.