I'm getting `warning: return discards qualifiers from pointer target
type' at line 11 on this code from gcc.
Some people suggested in old posts that this kind of warning can be
suppressed by qualifying the return type with const. In this code it
also can be removed by removing const from the first pointer parameter
str. Are there better ways to do it, or does it deserve to do this?
/* Search str for sub and return the pointer to the beginning of the
first occurence, or return null for no match. */
char *strstr(const char *str, const char *sub)
{
int i, j;
for (i = 0; str[i]; i++)
{
for (j = 0; sub[j]; j++)
if (str[i + j] != sub[j])
break;
if (!sub[j])
return &str[i]; /*line 11*/
}
return 0;
}
Thank you for your time.