Suppose I have a function which takes an argv-style pseudo-matrix
and modifies neither the strings nor the pointers. How do I
use the const qualifier to signal my intentions w/o drawing compiler
warnings? E.g.,
int
sum_of_lengths_of_strings( const char **s, int ns )
{
int i, len = 0;
for ( i = 0; i < ns; ++i )
len += strlen(s[i]);
return len;
}
int
main(int argc, char **argv )
{
printf( "command args len = %d\n",
sum_of_lengths_of_strings( argv, argc );
return 0;
}
This code draws a warning about incompatable types. Presumably
the compiler does this to guard against this situation:
void
get_a_const_string( const char **s )
{
*s = "better_not_modify_me";
}
However, even if we change the declaration of
sum_of_lengths_of_strings() to
int
sum_of_lengths_of_strings( const *const *s, int ns )
we still get the warning (at least w/ gcc).
Any ideas how to declare my intensions with const and not draw a
warning from the compiler?