I have a function that specifies a const parameter to indicate to the caller that it won't be modfied:
int func1(const char *some_string)
{
// Do something non-destructive with some_string
}
I pass a non-const variable as an argument to func1
:
int func2(void)
{
char *my_string = "my text";
func1(my_string);
}
gcc reports:
warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
What is the correct way to deal with this situation? Creating a const copy of my_string
seems a bit much, but simply casting seems like burying the warning.