Re: Utility to ensure appropriate headers were included



On Sun, 24 Feb 2008 04:02:31 -0800, Tomás Ó hÉilidhe wrote:
Recently, there was a Linux program distributed as source code, and it
compiled fine on the majority of systems. However on some systems, it
failed to compile. On some of these systems, people were getting errors
for undeclared tokens, while others were getting linking errors.

Anyway, the problem was that one of the source files was missing:

#include <stdio.h>

This wasn't a problem on most systems because some of the other header
files that were included actually included stdio.h.

Is there any utility out there that will process a source file and
notify you if you're depending on a declaration that isn't present in a
header file that's included directly in the source file?

What exactly do you mean?

a.c:
#include <stdio.h>
int myputchar(char c) { return putchar(c); }

b.c:
#include "b.h"
int myputchar(char c) { return putchar(c); }

b.h:
#include <stdio.h>

c.c:
#include <curses.h>
int myputchar(char c) { return putchar(c); }

For which files do you want a notification? I'm guessing you want none for
a, and one for c. I don't know about b. However, what if <stdio.h> doesn't
define putchar, but instead includes a non-standard header which does? On
such a system (mine happens to declare putchar in <stdio.h> and define it
in <bits/stdio.h>, but the problem does exist for several other standard
library headers) there's really no difference between a and c that any
tool could tell without special built-in knowledge. So what do you want
the tool to do?
.



Relevant Pages

  • Re: Splitting up code ?
    ... compile the first source file and it defines storage for the global ... The opposite situation is that header guards can sometimes cause a source ... functions and global variables. ...
    (comp.lang.c)
  • Re: Utility to ensure appropriate headers were included
    ... failed to compile. ... This wasn't a problem on most systems because some of the other header ... a header file that's included directly in the source file? ... Your program that happens to use and that calls puts can ...
    (comp.lang.c)
  • Re: Splitting up code ?
    ... I then compile the second source file and it defines storage ... > header file with guards. ... > functions and global variables. ...
    (comp.lang.c)
  • Re: What is a header?
    ... I understand this is all preprocessed to render the actual header that goes ... > of a source file. ... necessary to compile and link it separately, ... > within the class definition are inline by default. ...
    (comp.lang.cpp)
  • intrestring puzzle
    ... The following source file does not compile. ... int main ... itsValue shud b private. ...
    (comp.lang.cpp)

Loading