On 13 Nov 2006 15:30:47 -0800, "wanwan" <er*******@yahoo.comwrote in
comp.lang.c:
Hi,
I have a project with multiple c files. Some of these modules have
functions that have the same name and their operations are exactly the
same.
Your description is not clear. C does not have "modules". C has
"translation units". In general terms, a translation unit consists of
what we usually call a source file and any headers and anything else
it includes.
My rusty memory tells me there is a way with preprocessor directives to
make sure these functions are not included more than once, but I forgot
how to.
There is no preprocessor directive that can help you if you have more
than one source file that defines a function with external linkage and
the same name. Other than the nasty macros in each file (or all but
one) redefining the name. But it is better to rename them yourself.
Can somebody please give me an example?
If you have defined functions or objects in header files without the
static keyword and included such header files in more than one source
file, there is nothing the preprocessor can do, either.
You need to post a cut-down sample, such as a header file and two
source files that contain such functions. But the best option is not
to do that.
A function should be defined in exactly one source file. A prototype
for that function should be placed in a header file. That header file
should be included in the source file that defines the function, and
also in any other source files that want to call the function.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html