checking man page includes and prototypes?
Tom Rhodes
trhodes at FreeBSD.org
Wed Jun 14 16:59:56 UTC 2006
On Wed, 14 Jun 2006 09:15:39 -0700
Rich Morin <rdm at cfcl.com> wrote:
> I'm doing a lot of editing of section 2 and 3 man pages,
> concentrating on the includes and prototypes. Although
> I'm trying to be careful, it's quite likely that some
> errors will slip past me. So, I'm casting about for a
> way to do an automated sanity check. Here's one idea:
>
> For each man page
> For each prototype
> Construct a C test file.
> Compile the test file.
> Look for nastygrams, etc.
>
> For example, the sysconf(3) SYNOPSIS contains the lines:
>
> #include <unistd.h>
>
> long
> sysconf(int name);
>
> I can turn this into the file test.c:
>
> #include <unistd.h>
>
> main() {
>
> int name;
> sysconf(name);
> }
>
> Compiling this (e.g., "cc test.c") finishes silently.
> So far, so good...
>
>
> Editing "sysconf" into "sysconfx" produces a promising
> nastygram:
>
> /usr/bin/ld: Undefined symbols:
> _sysconfx
> collect2: ld returned 1 exit status
>
>
> However, editing "int name;" into "float name;' does
> NOT cause a nastygram. So, it appears that prototype
> checking is not being done. The gcc(1) man page gave
> me the idea of trying
>
> gcc -pedantic -ansi test.c
>
> but this didn't make any visible difference. I see a
> bazillion other options, including a bunch of "-W..."
> goodies, but I'd rather not try them all at random. I
> tried "gcc -pedantic -ansi -Wstrict-prototypes test.c",
> but it only complained about my "main" statement (?):
>
> test.c:3: warning: function declaration isn't a prototype
>
>
> Any suggestions (general or specific) on how I might be
> able to cajole gcc (or whatever) into helping me?
>
> -r
>
> P.S. The "obvious" strategy of inspecting the header file(s)
> breaks down under closer examination. The declaration
> may be located in an include file which is referenced
> indirectly, #defines or #ifdefs may be involved, etc.
>
> So, for a general, automated solution, I'd like to rely
> on the compiler (etc) to tell me whether the usage is
> complete and correct.
Have you tried using cc with -Wall?
Lemmie sleep some and I might come up with something else.
--
Tom Rhodes
More information about the freebsd-doc
mailing list