char *'s and const char *'s

Richard Caley rjc at uk.ac.ed.cstr
Sun Jan 13 07:02:18 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 * [...]

    The question: What is the method preferred/recommended by
    professionals and other experienced individuals?

I don't know about the high muckerty muck profesional types, but my
first move would be to shout at the person responsible for the
decalration. 

Of course, you have to be quite sure that the function really does not
do anything to the string. Just because it is obvious it should not,
that does not mean it won't just for the hell of it.

Quick quiz: which three letter workstation manufacturer's `sscanf'
writes to its first argument... Answers on a letter bomb to...

--
rjc at cstr.ed.ac.uk



More information about the Comp.lang.c mailing list