char *'s and const char *'s
Doug Gwyn
gwyn at smoke.brl.mil
Sat Jan 12 10:07:27 AEST 1991
In article <1991Jan11.182945.5437 at nntp-server.caltech.edu> bruce at seismo.gps.caltech.edu (Bruce Worden) writes:
>Given:
>int foo(char *file);
>And knowing that foo() really only needs a const char *, it is often called as:
> a = foo("myfile");
>but a kindly compiler will warn something like:
> junk.c:7: warning: argument passing of non-const * pointer from const *
You should have declared foo as int foo(const char *file). No diagnostic
should be generated when a pointer to non-const char is passed as an
argument to the function, and of course no diagnostic would be issued
for a pointer to const char either.
More information about the Comp.lang.c
mailing list