473,381 Members | 1,446 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,381 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 1763
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: 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: 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:
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.