Expert C Programming

(Jeff_L) #1

char strcpy(char , const char * );


Don't omit the parameter names. Although the compiler doesn't check these, they often
convey extra semantic information to the programmer. Similarly, the definition of the
function has changed from


char * strcpy(dst, src)


char dst, src;


{ ... }


to


char strcpy(char dst, const char src) / note no


semi-colon! */


{ ... }


Instead of being ended with a semicolon, the function header is now directly followed by a
single compound statement comprising the body of the function.


Prototype everything new you write and ensure the prototype is in scope for every call.
Don't go back to prototype your old K&R code, unless you take into account the default
type promotions—more about this in Chapter 8.


Having all these different terms for the same thing can be a little mystifying. It's rather like the way
drugs have at least three names: the chemical name, the manufacturer 's brand name, and the street
name.


Reading the ANSI C Standard for Fun, Pleasure, and Profit


Sometimes it takes considerable concentration to read the ANSI C Standard and obtain an answer
from it. A sales engineer sent the following piece of code into the compiler group at Sun as a test case.


1 foo(const char **p) { }


2


3 main(int argc, char **argv)


4{


5 foo(argv);


6}


If you try compiling it, you'll notice that the compiler issues a warning message, saying:


line 5: warning: argument is incompatible with prototype


The submitter of the code wanted to know why the warning message was generated, and what part of
the ANSI C Standard mandated this. After all, he reasoned,

Free download pdf