char *'s and const char *'s
Bruce Worden
bruce at seismo.gps.caltech.edu
Sat Jan 12 05:29:45 AEST 1991
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 *
A possible solution is:
char str[] = "myfile";
.
.
.
a = foo(str);
but this distances the file name from the function call (a minor
inconvenience). The question: What is the method preferred/recommended by
professionals and other experienced individuals?
--------------------------------------------------------------------------
C. Bruce Worden bruce at seismo.gps.caltech.edu
252-21 Seismological Laboratory, Caltech, Pasadena, CA 91125
More information about the Comp.lang.c
mailing list