typechecking
Bennett Todd
bet at dukeac.UUCP
Wed Jan 18 18:22:21 AEST 1989
To get gcc to typecheck parameters to functions you need to have function
prototypes. I have an include file (I posted it here earlier) which contains
ANSI-style function prototypes for all the routines in sections 2 and 3 of the
UNIX Programmer's Manual. I've since enhanced it to include proper "const"
qualifiers (as best I can, I might have still missed some) so that I now can
compile with gcc's "-Wall -Wwrite-strings" options, which gives pretty
aggressive checking. If anybody is interested in this file let me know. As it
stands it #include's everything under the sun; I like this. It doesn't seem to
incur any run-time overhead in space or time (by which I mean to say that the
unneeded declarations and includes don't seem to change the generated code)
and I don't have to #include any of the system files. If you didn't like this
behavior the file could be split into separate sets of function prototypes
which could be imbedded (within #ifdef __STDC__ / #endif) in the appropriate
/usr/include files.
Specifically, to get gcc to give the desired warning on the common error
fprintf("format", args);
(omitting the needed stream parameter) you would want the following prototype
in scope:
int fprintf(FILE *, const char *, ...);
-Bennett
bet at orion.mc.duke.edu
More information about the Comp.lang.c
mailing list