473,387 Members | 1,536 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,387 software developers and data experts.

Including headers only once

I have a header file that I want to share among various files, and I use:

#ifndef UTIL_H_
#define UTIL_H_

file contents
#endif

But the compiler gives me an error

What should I do?
Nov 13 '05 #1
3 1764
Miguel <mf**@mega.ist.utl.pt> scribbled the following:
I have a header file that I want to share among various files, and I use: #ifndef UTIL_H_
#define UTIL_H_ file contents
#endif But the compiler gives me an error What should I do?


Telling us what the error says would be a start.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
Nov 13 '05 #2
Miguel <mf**@mega.ist.utl.pt> wrote:
I have a header file that I want to share among various files, and I use:

#ifndef UTIL_H_
#define UTIL_H_

file contents
#endif

But the compiler gives me an error

What should I do?


What is the error?
--
== Eric Gorr ========= http://www.ericgorr.net ========= ICQ:9293199 ===
"Therefore the considerations of the intelligent always include both
benefit and harm." - Sun Tzu
== Insults, like violence, are the last refuge of the incompetent... ===
Nov 13 '05 #3
Miguel <mf**@mega.ist.utl.pt> wrote:
I have a header file that I want to share among various files, and I use: #ifndef UTIL_H_
#define UTIL_H_ file contents
#endif But the compiler gives me an error


The compiler probably doesn't, but the linker might if you
have concrete definitions in the header.

For example, if you have a line such as

int a; /* notice, no extern */

in the header file, you are creating the int object 'a' with
external linkage rather than saying that one such object exists
elsewhere as you would by prefixing your definition with
'extern' and making it into a declaration.

Now, when you are including this header file multiple times
in the same translation unit, there is no problem because
of your include guards. However, if are attempting to link
two or more object files which were generated from separate
translation units, each of which having included it's own copy
of the header, then you will get a clash because the
external linkage object is defined more than once.

Alex
Nov 13 '05 #4

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

Similar topics

11
by: cppaddict | last post by:
Say that your CustomClass.h header files requires #include <string> Now say that your CustomClass.cpp file also requires string. Is it good form to repeat the <string> include to make the...
1
by: Ben | last post by:
Hi guys, this *should* be a simple problem, but I've never really got my head around it. I'm hoping somebody on this message board could help me out? I don't really have any experience with VS.NET,...
8
by: nrhayyal | last post by:
Hi c++ Gurus, Need your blessing. while testing few aspects with respect to header file inclusions, i observed few things which i would like to share with you. i have a file sqlca.h in which a...
15
by: spibou | last post by:
My understanding is that when you write a library then the header should be of the form #ifndef macro_corresponding_to_the_library #define macro_corresponding_to_the_library .. .. ...
2
by: Spartacus | last post by:
Hello, I know there is lots of information out there and I've taken a look, but I want to learn how to do this myself. And I'm a beginner here and some of it I don't understand (so no flames,...
5
by: =?Utf-8?B?SmltbWVy?= | last post by:
Hello, I've been trying to create a WCF SOAP Router Service that can forward not just the message body but also any security headers set by the originator of the message. The destination service...
8
by: nguillot | last post by:
Hello. If I have the following classes: class B {}; typedef B tB; if A is: class A
8
by: J Kenneth King | last post by:
Hey everyone, I'm working on a python extension wrapper around Rob Hess' implementation of a SIFT feature detector. I'm working on a computer-vision based project that requires interfacing with...
6
Markus
by: Markus | last post by:
Things to discuss: Headers What are they? What does PHP have to do with headers? Why can they only be sent before any output? Common causes
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
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,...
0
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...
0
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,...

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.