473,385 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

tool to check multiple inclusion of header file

I am looking for a tool that can scan my soyrce code and check if a
header file gets included more then once in a sequece of compiled code.
Can some one guide me to such a tool !!

Mar 14 '06 #1
6 5159
Hi,
Multiple inclusion can be easily avoided by inserting Inclusion
guards on each headefiles. Follow it while creating any header file.
Then you need not have to worry about the multiple inclusion problem. I
will give an example for inclusion guard.

If your header is somthing like Reader.h, in Reader.h you write,

#ifndef _READER_H_
#define _READER_H_

// Put your complete header code here

// And at the end you put,
#endif //_READER_H_ ends here.

Now there cannot be multiple inclusions. Because when you include
Reader.h first time "_READER_H_" gets defined and the file gets
included. But when you try to include it again "_READER_H_" is already
defined and so the Reader.h will not be included.

Best regards,
Amal P.

Mar 14 '06 #2

Amal P wrote:
If your header is somthing like Reader.h, in Reader.h you write,

#ifndef _READER_H_
#define _READER_H_

// Put your complete header code here

// And at the end you put,
#endif //_READER_H_ ends here.


Just a small nit: names that start with an underscore followed by an
uppercase letter are reserved for the implementation. You should not
use them in your own code. So READER_H_ would be a better choice.

Gavin Deane

Mar 14 '06 #3
Hi Gavin,
Well its not like that. It's just some programming style. You can
actually use these names. There are a few other places where these kind
of names are used. Suppose i am building a big library and I want
others to use it. There I declare names starting with underscore and
write it to mean that is my system (The whole software as it is). The
most convenient way that I found out is you keep your own name n number
for this. So lets say you have <Some-File-Name>.h is the file. So
please take this name and give
#ifndef _<Some-file-name><DATE stamp><Time stamp>
Or something like that.

Mar 14 '06 #4
[replying to a statement that names starting with an underscore
followed by a capital letter...]
Student wrote:
Well its not like that. It's just some programming style.


False. I can back-up the claim that names starting with an underscore
followed by a capital letter are reserved in all contexts for the
standard C++ library implementation quoting the standard:

17.4.3.1 (lib.reserved.names), paragraph 3:
If the program declares or defines a name in a context where it
is reserved, other than as explicitly allowed by this clause, the
behavior is undefined.

17.4.3.1.2 (lib.global.names), paragraph 1, first bullet:
Each name that contains a double underscore ("__") or begins with
an underscore followed by an uppercase letter (lex.key) is
reserved to the implementation for any use.

Your turn!
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Mar 14 '06 #5
Please quote some context. From Google Groups, don't use the Reply link
at the bottom of the message, click on Show Options at the top of the
message and use the Reply link revealed there. I wrote:

Just a small nit: names that start with an underscore followed by an
uppercase letter are reserved for the implementation. You should not
use them in your own code. So READER_H_ would be a better choice.

Student wrote:
Hi Gavin,
Well its not like that.
It is.
It's just some programming style.
It's not.
You can actually use these names.
You *can*, and you may get away with no problems. I said you *should
not*. The language standard agrees with me.

17.4.3.1.2
Certain sets of names and function signatures are always reserved to
the implementation:
- Each name that contains a double underscore (_ _) or begins with an
underscore followed by an uppercase letter is reserved to the
implementation for any use.
- Each name that begins with an underscore is reserved to the
implementation for use as a name in the global namespace.

As I said, this is a relatively minor point. But once you know them,
the rules are very simple and help ensure that you will not have name
clashes with the implementation.
There are a few other places where these kind
of names are used. Suppose i am building a big library and I want
others to use it. There I declare names starting with underscore and
write it to mean that is my system (The whole software as it is).
What happens if my program uses your library and someone else's library
too, and you have both used that naming convention? Why not just put
your library in its own namespace?
The most convenient way that I found out is you keep your own name n number
for this. So lets say you have <Some-File-Name>.h is the file. So
please take this name and give
#ifndef _<Some-file-name><DATE stamp><Time stamp>
Or something like that.


Something like that, yes - just without the leading underscore.

Gavin Deane

Mar 14 '06 #6

Gavin Deane wrote:
Please quote some context. From Google Groups, don't use the Reply link
at the bottom of the message, click on Show Options at the top of the
message and use the Reply link revealed there. I wrote:

Just a small nit: names that start with an underscore followed by an
uppercase letter are reserved for the implementation. You should not
use them in your own code. So READER_H_ would be a better choice.

Student wrote:
You can actually use these names.
You *can*, and you may get away with no problems. I said you *should
not*. The language standard agrees with me.


Actually, the standard is stronger than that. See Dietmar Kuehl's post.
Using reserved names is undefined behaviour 17.4.3.1/3. So as with all
undefined behaviour, if you choose to rely on it, all bets are off.

To repeat from my previous post: As I said, this is a relatively minor point. But once you know them,
the rules are very simple and help ensure that you will not have name
clashes with the implementation.

.... and that you will avoid undefined behaviour.

Gavin Deane

Mar 14 '06 #7

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

Similar topics

2
by: Jochen Zeischka | last post by:
Hi everybody! I have a question concerning code organisation. Suppose I have the following header file: #ifndef SOME_NAME #define SOME_NAME namespace N { void F()
14
by: Fritz Foetzl | last post by:
I'm flummoxed. I'm a veteran C++ programmer from the Unix/Linux camp, trying to learn Visual C++. I'm trying to build a project in which I need to include one header in a couple of different files,...
1
by: mead | last post by:
This is from an article: "Given a.h and a.cpp files, a.h has been included as the first header file in a.cpp. This will make sure that a.h does not expect a certain header files to be included...
6
by: techBoy | last post by:
I am looking for a tool which can scan my source code and tell me if a header file gets included more then once in a sequence of source file or header files. Can some one guide me to such a tool !!
11
by: lars.uffmann | last post by:
Easily described problem: Using g++ version 3.3.5 under suse 9.3, bla.h: ----------- #ifndef myTEST #define myTEST ZFSInt test; #endif
8
by: ewpatton | last post by:
I have a header that is shared among different CPP files for constants. When Microsoft Visual C++ links the .obj files, it complains that these names are all duplicates. How can I get it to realize...
10
by: zfareed | last post by:
Similar problem to the previous post. I have created a project with about 7 files including 3 header files and 3 implementation files. I am getting a multiple definition error when compiling for...
14
by: Martin Wells | last post by:
When I have errors in a program, whether they be compiler errors, linker errors, or if the program crashes when running, I have a list of things I check for initially. If I get an error for...
37
by: C_guy | last post by:
Does anyone know of a (hopefully free) tool that can traverse a project and determine which "#include"s are not needed or needed in every .C file? This would be helpful in removing header...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.