Re: Utility to ensure appropriate headers were included
- From: Harald van Dijk <truedfx@xxxxxxxxx>
- Date: Sun, 24 Feb 2008 18:13:37 +0100
On Sun, 24 Feb 2008 17:01:13 +0000, Richard Tobin wrote:
In article
<5649c69f-79d8-4e6f-a9a8-181b86a0f35c@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Tomás Ó hÉilidhe <toe@xxxxxxxxxxx> 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.
Presumably you mean that one of the system headers included stdio.h,
because if it was one of the program's headers this wouldn't be a
problem on "some systems".
I'm not sure to what extent this is permitted for standard C headers.
Not at all, except in specific cases under the as-if rule.
Presumably it's allowed, because all the identifiers they declare are
reserved. Perhaps someone can quote chapter and verse on this.
Most aren't reserved (except as external identifiers) unless the header is
included; part of 7.1.3p1 is:
"Each identifier with file scope listed in any of the following subclauses
(including the future library directions) is reserved for use as a macro
name and as an identifier with file scope in the same name space if any
of its associated headers is included."
This is a strictly conforming program:
#include <stdlib.h>
static int puts = 3;
int main(void) {
return puts - 3;
}
and it wouldn't work if <stdlib.h> includes <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?
I don't think that's possible, since it's perfectly legal for, say,
stdio.h to work by including some other system headers that declares
printf().
Right.
.
- Follow-Ups:
- Re: Utility to ensure appropriate headers were included
- From: CBFalconer
- Re: Utility to ensure appropriate headers were included
- References:
- Utility to ensure appropriate headers were included
- From: Tomás Ó hÉilidhe
- Re: Utility to ensure appropriate headers were included
- From: Richard Tobin
- Utility to ensure appropriate headers were included
- Prev by Date: Re: Converting unsigned long to string in C
- Next by Date: execute command line arguments
- Previous by thread: Re: Utility to ensure appropriate headers were included
- Next by thread: Re: Utility to ensure appropriate headers were included
- Index(es):
Relevant Pages
|