473,287 Members | 1,899 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,287 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 5151
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.