473,387 Members | 1,575 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.

Header file with function implementation problem

Hello All

Received a header file from a supplier that defines an interface to
implement but it's giving me a problem, I reproduce the general
structure of the header file below;

#ifndef XYZ_H

various #define(s)

#ifndef _ABC

void someFunc();

void someOtherFunc();

void implementedFunc() {
xyz;
}

#endif

#endif

The problem is that all my files that include this header xyz.h
complains about multiple definition of symbol implemetedFunc().

We are running HP-UX on Itanium.

Any advice would be appreciated.

Thank you,

B
Jun 27 '08 #1
7 2961
bcpkh <va**************@gmail.comwrites:
Hello All

Received a header file from a supplier that defines an interface to
implement but it's giving me a problem, I reproduce the general
structure of the header file below;

#ifndef XYZ_H

various #define(s)

#ifndef _ABC

void someFunc();

void someOtherFunc();

void implementedFunc() {
xyz;
}

#endif

#endif

The problem is that all my files that include this header xyz.h
complains about multiple definition of symbol implemetedFunc().

We are running HP-UX on Itanium.

Any advice would be appreciated.
Function definitions don't belong in headers.

You said that the header "defines in interface to implement". Perhaps
the implementation of implementedFunc is just shown as an example. If
you're expected to modify the header for your own use anyway, it's not
much of a problem. If you're expected to use it as is, complain to
the supplier.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #2
On Jun 10, 5:47 pm, Keith Thompson <ks...@mib.orgwrote:
bcpkh <vanheerden.br...@gmail.comwrites:
The problem is that all my files that include this header xyz.h
complains about multiple definition of symbol implemetedFunc().
Function definitions don't belong in headers.
What about static / inline / static inline functions?
Jun 27 '08 #3
bcpkh wrote:
Received a header file from a supplier that defines an interface to
implement but it's giving me a problem, I reproduce the general
structure of the header file below;

#ifndef XYZ_H

various #define(s)
Did you remember to #define XYZ_H here? Without that, your header guard
does nothing.
#ifndef _ABC

void someFunc();

void someOtherFunc();

void implementedFunc() {
xyz;
}

#endif

#endif

The problem is that all my files that include this header xyz.h
complains about multiple definition of symbol implemetedFunc().
Unless the function is static (and preferably inline too), the
definition should not be in a header, only a declaration. All normal
function definitions go in a .c file.

S
Jun 27 '08 #4
On Tue, 10 Jun 2008 09:36:20 -0700 (PDT), bcpkh
<va**************@gmail.comwrote:
>Hello All

Received a header file from a supplier that defines an interface to
implement but it's giving me a problem, I reproduce the general
structure of the header file below;

#ifndef XYZ_H

various #define(s)
Can we assume one of these is for XYZ_H?
>
#ifndef _ABC

void someFunc();
You do realize that none of these are valid prototypes. Hopefully
*you* left out the parameter specifications for the sake of brevity
and they are included in the header.
>
void someOtherFunc();

void implementedFunc() {
xyz;
}
This is not a declaration but a definition. And still not a
prototype.
>
#endif

#endif

The problem is that all my files that include this header xyz.h
complains about multiple definition of symbol implemetedFunc().
The include guard (XYZ_H) only protects you from multiple inclusion in
the same translation unit (source file) and then only if there is a
#define directive for it in some of the code you omitted.

The multiple definition guard (_ABC) requires you to decide in which
source file (singular) you want the definition of implementedFunc to
appear. In all other source files, you need to include the
preprocessing directive
#define _ABC
so that the compiler will know to skip over the definition of
implementedFunc. Without this directive, implementedFunc will be
compiled with each source file that includes xyz.h and the linker will
correctly report that it is defined multiple times.

By the way, this approach sucks. At the very least the test should be
reversed so you only have to specify _ABC once instead on n-1 times.
But functions and objects should never be defined in a header file
anyway, only declared. The supplier should provide you either
1 - the object file for implementedFunc in a format suitable for
your linker, or
2 - the source file for implementedFunc separate from xyz.h so
you can compile it yourself.
Remove del for email
Jun 27 '08 #5
On Jun 10, 12:36 pm, bcpkh <vanheerden.br...@gmail.comwrote:
Hello All

Received a header file from a supplier that defines an interface to
implement but it's giving me a problem, I reproduce the general
structure of the header file below;

#ifndef XYZ_H

various #define(s)

#ifndef _ABC

void someFunc();

void someOtherFunc();

void implementedFunc() {
xyz;

}

#endif

#endif

The problem is that all my files that include this header xyz.h
complains about multiple definition of symbol implemetedFunc().

We are running HP-UX on Itanium.

Any advice would be appreciated.

Thank you,

B
The header file multiple inclusion is not implemented correctly.

The following article should help:

http://www.eventhelix.com/realtimema...dePatterns.htm

--
http://www.EventHelix.com/EventStudio
Sequence diagram based systems engineering tool
Jun 27 '08 #6
viza wrote:
On Jun 10, 5:47 pm, Keith Thompson <ks...@mib.orgwrote:
>bcpkh <vanheerden.br...@gmail.comwrites:
>>The problem is that all my files that include this header xyz.h
complains about multiple definition of symbol implemetedFunc().
>Function definitions don't belong in headers.

What about static / inline / static inline functions?
They are OK, your example was neither.

--
Ian Collins.
Jun 27 '08 #7
EventHelix.com said:

<snip>
The header file multiple inclusion is not implemented correctly.

The following article should help:

http://www.eventhelix.com/realtimema...dePatterns.htm
Unlikely, since it seems to be about C++ rather than C.

It is generally a bad idea to assume that C++ rules are the same as C rules
for features that they have in common. It does sometimes turn out to be
the case, but it is still a poor assumption. If you have an article about
the C preprocessor rather than the C++ preprocessor, bring it on.

I note that the first code example on your page, if taken as C, invades
implementation namespace (whether that rule is the same in C++, I don't
know), and then rounds off with a multitude of syntax errors.

--
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
Jun 27 '08 #8

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

Similar topics

3
by: dharmesh Gupta | last post by:
Hi All, i am new to header files , and have a basic question , i have made my program in three files namely, idr_bpl.cpp( contains class definitions and function definitions) bpl.cpp(...
31
by: Steven T. Hatton | last post by:
If a header is not necessarily a source file, and the sequences delimited by < and > in header names aren't necessarily valid source file names, what exactly is a header? -- p->m == (*p).m == p.m...
16
by: matthurne | last post by:
I just started learning C++ on my own...I'm using Accelerated C++. Something it hasn't explained and I keep wondering about is how header files actually work. I suspect it doesn't get into it...
11
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
9
by: Mathieu Malaterre | last post by:
Hello, This thread follow my previous one on the gcc mailing list. Basically I -still- have a problem in my code. I define in a header file: static const std::string foo = "bar"; Which not...
15
by: Kannan Goundan | last post by:
Maintaining a C++ header file can be painful. I want a way to automatically generate header files from the implementation file. Does anybody know of a program that does this? If not, I'd like...
3
by: pooja | last post by:
Suppose i have created a class c1 with f1()in c1.cpp and included this c1.cpp in file1.cpp file , which is also having main() by giving the statement #include "c1.cpp". the same i can do by...
24
by: ypjofficial | last post by:
Hello all, I have written a class with many private data members.and i am putting it in a separate dll file. Now when i link that file while writing my main program module,natuarally i have to...
16
by: wdh3rd | last post by:
Hi everyone. I'm new to C and I have a few questions: I am making files for permutations and combinations. Files to be made are perm.c, perm.h, combo.c, and combo.h. Since both combinations...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.