473,657 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Utility to ensure appropriate headers were included


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?
Feb 24 '08 #1
9 1416
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?
Yes, that utility is called a C compiler.
Normally, all compilers will warn you about missing declarations.
The problem is that people think that compiling means just
"press 'compile' in the IDE" and ignore completely the errors
or warnings that the compiler prints.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Feb 24 '08 #2
jacob navia said:
Tomás Ó hÉilidhe wrote:
<snip>
>>
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?

Yes, that utility is called a C compiler.
You appear to have mis-read the question.
Normally, all compilers will warn you about missing declarations.
He's not talking about missing declarations. He's talking about
declarations that depend on a header that is included indirectly by
another header.
The problem is that people think that compiling means just
"press 'compile' in the IDE" and ignore completely the errors
or warnings that the compiler prints.
No, that isn't the problem. It's *a* problem, but it's not *this* problem.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Feb 24 '08 #3
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.hdoesn 't
define putchar, but instead includes a non-standard header which does? On
such a system (mine happens to declare putchar in <stdio.hand 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?
Feb 24 '08 #4
In article <56************ *************** *******@q33g200 0hsh.googlegrou ps.com>,
Tomás Ó hÉilidhe <to*@lavabit.co mwrote:
>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.
Presumably it's allowed, because all the identifiers they declare are
reserved. Perhaps someone can quote chapter and verse on this.
>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().

-- Richard

--
:wq
Feb 24 '08 #5
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".

Not necessarily. The code could have used some other shared headers,
something like:

#include <openssl/decrypt.h>

The newer version of "decrypt.h" might not include <stdio.h>.
Feb 24 '08 #6
On Feb 24, 4:02 am, "Tomás Ó hÉilidhe" <t...@lavabit.c omwrote:
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.
Indeed, a good question. One not addressed by the C standard. One
can see how the claims of portability seem highly exaggerated in light
of this.
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?
Well ... I am unaware of such a utility.

But you could build one manually, probably. The main purpose of the
standard library header files are to declare prototypes and some
typedefs. So what you could do is copy your compiler's header files
to a separate directory structure somewhere, manually remove all
#include's from those header files (easier said than done) then point
your compiler's STD LIB include directory to that directory and try a
test compile. You should not expect this to properly link -- in fact
you should get errors, but at least it should compile.

The hard part, I suppose, is building a set of include files that
truly represented the absolute minimum support that the C language.
Some of the structures defined may have fields that depend on the
inclusion of other header files, for example. But I suppose this is a
doable exercise over a few days, maybe, if one started with a
compiler's header files, and the C standard, and just worked through
them.

You didn't think writing portable C code was going to be easy did you?

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/
Feb 25 '08 #7
In article <db************ *************** @cache4.tilbu1. nb.home.nl>,
Harald van Dijk <tr*****@gmail. comwrote:
>They're reserved "for use as identifiers with external linkage" when their
standard headers are not included, and they are reserved "for use as a
macro name and as an identifier with file scope in the same name space" if
they are.
Incidentally, I find this wording very unclear. "Reserved for use as X"
naturally means "can only be used as X", but is presumably intended to
mean "reserved in such a way that the user mustn't re-use them as X".

-- Richard
--
:wq
Feb 25 '08 #8
On Mon, 25 Feb 2008 22:15:47 +0000, Richard Tobin wrote:
In article <db************ *************** @cache4.tilbu1. nb.home.nl>,
Harald van Dijk <tr*****@gmail. comwrote:
>>They're reserved "for use as identifiers with external linkage" when
their standard headers are not included, and they are reserved "for use
as a macro name and as an identifier with file scope in the same name
space" if they are.

Incidentally, I find this wording very unclear. "Reserved for use as X"
naturally means "can only be used as X", but is presumably intended to
mean "reserved in such a way that the user mustn't re-use them as X".
It can be read from the implementation' s viewpoint: the implementation can
only use puts in the ways directly specified in the standard (and mustn't
interfere with any other ways it might be used in user code).
Feb 25 '08 #9
Keith Thompson wrote:
CBFalconer <cb********@yah oo.comwrites:
.... snip ...
>
>Well, I reread the quoted part, and it seems to me that any
compiler should spit out some 'undefined' error messages. You
can't say a missing definition belongs in any particular file.
The fact that functions require prototypes in C99 should help.
Maybe I am thick.

The key word is *directly*. For example, if a program calls
printf, it should have "#include <stdio.h>". If another header
the program includes, say "foo.h", happens to include <stdio.h>,
then the program will compile without error -- until it's
recompiled on a system where "foo.h" *doesn't* happen to include
<stdio.h>. What Tomás is looking for is a utility that will
warn about this kind of problem.
Oh, I see. However, that sort of problem is basic to his include
philosophy. When he writes the module that includes foo.h, and
needs access to printf, he should have included stdio.h himself.
stdio.h (and all standard include files) has protections against
any problems due to multiple inclusion.

However, I suspect that a decent cross-reference utility will do
the job for him.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Feb 25 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2239
by: Rick | last post by:
When using the load utility on a CSV file, it seems I always need to edit the input file and add an extra comma after the last field in order for MySql to parse the line properly. I use a command like: LOAD DATA INFILE 'absolute path to file.csv' IGNORE INTO TABLE table-name FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED
1
1586
by: zerotyNONONOTHERESNOSPAMMING!type | last post by:
Hi, As most of you probably already know, depending on which implementation of C++ you have, #include <iostream> may cause various other headers to be #included too. (I've observed cstring, cstdio, cmath and I think cstdlib in g++) Are there any that the standard requires to be "dragged in" like this regardless of implementation?
2
10546
by: Mike Metzger | last post by:
I've been running an Access2000 database for a couple years on a Win2k machine fine. We tried to copy the database over to another machine that already had Access2000 installed. When we tried to run it, we got an error on the following piece of VBA code embedded in a form: ------------------------ With Me .AgeMax = DateDiff("yyyy", Me.dteDateOfBirthMin, Date) .AgeMin = DateDiff("yyyy", Me.dteDateOfBirthMax, Date) End With...
4
1982
by: Alexander Gorshenev | last post by:
I am looking for an elegant solution for the following problem: I have two projects for which I have to create a kind of bridge or translator between. For each of the projects there exist a set of headers included by practicaly all of the member .c files. For my bridge I would be using all those "main" headers from both of the projects included together. But unfortunately, due to historical reasons, those headers conflict in many...
9
1510
by: comp.lang.php | last post by:
<?php if (headers_sent()) print_r('headers sent'); // do other stuff ?> I have a file, "classes.inc.php", a library of PHP version 4+ classes. This library file, the moment it is included, causes headers to be generated into the HTTP headers! I have no explanation as to how it does that, it just does that! I have tried everything I can think of,
4
3297
by: Rui.Hu719 | last post by:
Hi, All: I read the following passage from a book: "There are three exceptions to the rule that headers should not contain definitions: classes, const objects whose value is known at compile time, and inline functions are all defined in headers. " Can someone explain to me why some of the const objects must be defined in the header file?
5
2472
by: tobiah | last post by:
In the example at: http://docs.python.org/lib/SMTP-example.html The text of the email message ends up with the From: and To: headers in it, and yet the call to sendmail() on the server object requires me to specify them again. Shouldn't smptlib just make the headers for me, given the 'from' and 'to' addresses? Perhaps this allows
3
1499
by: Paavo Helde | last post by:
C++ lets you declare functions in headers which are actually not defined in the source code. During a cleanup cycle for a library I would like to ensure that all free and member functions advertised in the library header files are actually defined inside the library. I could imagine a utility which processes the header files and spits out a piece of code which takes the address of each declared function. Missing definitions would then show...
5
1760
by: jodleren | last post by:
Hi all! I have this problem, that I need to check the user (using session data and some checks (included files)), then when ok, I can send a file to the user.... meaning (simplified): header("Pragma: no-cache"); header("Expires: -1"); session_start();
0
8420
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8516
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.