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!