473,289 Members | 1,940 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,289 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 2953
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...
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:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.