473,325 Members | 2,342 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,325 software developers and data experts.

same function name in different files

Hi,

I have come unto a situation where two source files of one project contain
similar functions with the same name (it reads settings from a file and thus
named FetchSettings).

When I compile this project, it complains about redefining FetchSettings.
What can I do to avoid this behaviour? Declare it static, maybe?!?

Although renaming the functions is definitaly an option, I am wondering how
to solve this issue. Thanks for any input,

--
Martijn
http://www.sereneconcepts.nl
Nov 13 '05 #1
3 5980
Martijn <su*********************@hotnofiltermail.com> wrote:
I have come unto a situation where two source files of one project contain
similar functions with the same name (it reads settings from a file and thus
named FetchSettings). When I compile this project, it complains about redefining FetchSettings.
What can I do to avoid this behaviour? Declare it static, maybe?!?


If the functions are only used within the file they are defined in, yes,
declaring them static should resolve the problem.

Regards, Jens
--
_ _____ _____
| ||_ _||_ _| Je***********@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring
Nov 13 '05 #2
Martijn wrote:
Hi,

I have come unto a situation where two source files of one project contain
similar functions with the same name (it reads settings from a file and
thus named FetchSettings).

When I compile this project, it complains about redefining FetchSettings.
What can I do to avoid this behaviour? Declare it static, maybe?!?
That's one option, but it makes a lot of sense to rename one of the
functions. If they have distinct prototypes, it'll be a lot easier to sort
out the mess.

Do check that they are two separate functions (different functionality); it
could be that one of them is just a slip of the mouse.

Although renaming the functions is definitaly an option, I am wondering
how
to solve this issue. Thanks for any input,


If you don't want to rename and static is an option, then use it, I guess.
It may not be an option if the functions are each called from more than one
translation unit.

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #3
Richard Heathfield wrote:
Martijn wrote:
I have come unto a situation where two source files of one
project contain similar functions with the same name (it reads
settings from a file and thus named FetchSettings).

When I compile this project, it complains about redefining
FetchSettings. What can I do to avoid this behaviour? Declare
it static, maybe?!?


That's one option, but it makes a lot of sense to rename one of
the functions. If they have distinct prototypes, it'll be a lot
easier to sort out the mess.

Do check that they are two separate functions (different
functionality); it could be that one of them is just a slip of
the mouse.
Although renaming the functions is definitaly an option, I am
wondering how to solve this issue. Thanks for any input,


If you don't want to rename and static is an option, then use it,
I guess. It may not be an option if the functions are each called
from more than one translation unit.


Whether or not he renames, the OP should probably mark them both
as static, and check that neither of them are mentioned in the
associated header file. As a general rule each source file should
declare all functions as static except those exported via the
header file (and main).

'static' is a very useful word for anything visible in file
scope. It keeps those items from being interfered with by
external entities, and from interfering with anything outside the
immediate compilation unit. When you see a static object you
immediately know that it is not affected by anything in any other
file. (Exception: if a pointer to it is passed out, which you can
detect in that source file alone.)

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #4

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

Similar topics

6
by: Krista | last post by:
Hi, I wrote a php project 2 years ago. I am totally lost right now. what is differnt between $userName, $_GET and $_REQUEST? In my past project, I remember i can use $userName as a variable, but i...
4
by: MLH | last post by:
A programmer developed an AMP (Apache/MySQL/PHP) application for me. When he was done, he sent me the PHP files and the MySQL dump file. Now, when I connect to the application on my LAN using...
5
by: Janick | last post by:
Following problem, hope someone can help us: We have a testserver with three test-databases for each of our current services (production servers are one machine per service). Having three databse...
19
by: Deniz Bahar | last post by:
Hi, I would like to call one of my functions the exact name as an existing C library function (for example K&R2 exercises asks me to make an atof function). If I don't include the header with...
1
by: David Gaudine | last post by:
(This is a bit like the recent thread "PHP Switching Sessions".) I use session_start(). When I open my web-based application in two windows on the same system, there's a definite clash; I can't...
0
by: Darrel | last post by:
I've been having problems trying to delete a file. I can upload and save the file no problem, but deleting it gives me two results: If I run the delete function from my app's unprotected (public)...
2
by: quickcur | last post by:
Hi, I used to have different c code in different files and compiled as different programs. For example, I have proc1.c: int x1, x2; void work1()
1
by: quickcur | last post by:
Hi, I used to have different c code in different files and compiled as different programs. For example, I have proc1.c: int x1, x2; void work1()
1
by: gomzi | last post by:
Hi, I would like to know as to how one could access a function having a same name but in different files. i.e. is there a way of specifying the name of the file so that the function could be...
10
by: parag_paul | last post by:
HI all, Suppose I have a huge code base, And I have a very common header file. Now there are mulitple places where this header file is kept. This header file cannot be factored as it has...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.