-Wcast-qual
在 stristr() 的return
行上输出此警告。问题是什么 ?
警告:cast 丢弃来自指针目标类型的限定符
char *stristr(const char *string, const char *substring)
{
size_t stringlength = strlen(string);
char *stringlowered = malloc(stringlength + 1);
strcpy(stringlowered, string);
tolower2(stringlowered); // in my source it has a different name, sorry.
char *substringlowered = malloc(strlen(substring) + 1);
strcpy(substringlowered, substring);
tolower2(substringlowered); // in my source it has a different name, sorry.
const char *returnvalue = strstr(stringlowered, substringlowered);
if(returnvalue != NULL)
{
size_t returnvaluelength = strlen(returnvalue);
returnvalue = string;
returnvalue += stringlength - returnvaluelength;
}
free(stringlowered);
free(substringlowered);
return (char *)returnvalue;
}
编辑:
在 glibc 2.15 的 strstr() 源代码中:
return (char *) haystack_start; // cast to (char *) from const char *