> I was wondering about C and namespaces.
C doesn't have namespaces - at least not in the way C++ has them
> How does the compiler/linker now know which implentation I refere to?
It doesn't, so what you get is a "multiply defined symbol" error.
> Is there anyway to avoid this problem, if it is a problem?
Choose better names
> Is this assumption correct?
Well you can use scope to some extent, by using the static keyword
Code:
static int findIndex( int i );
Now findIndex() cannot be seen outside the source file in which is it declared, so you could have both of them static in a.c and b.c, and all would be well.
> In larger programs it seems to me that it would be impossible to know the names of
> all declared functions
True - but the usual way round that is to adopt a more rigorous naming convention. This is one possible way of doing this.
If you have two modules foo.c and bar.c (and respective .h files)
All global symbols would be like
int Foo_Init ( void );
void Bar_Count ( int num );
All local symbols would be like
static foo_Count ( int num );
You prefix the symbol name with the name of the module, and you use case to denote scope.
> I have tried testing this with gcc by declaring and implementing a dummy function strlen
There's a lot going on here
1. gcc can inline certain standard library functions
To disable this, you need to compile with -fno-builtin
2. strlen is also a library function, which means if you declare yours first, the one in the library will be quietly ignored.
Libraries of symbols are searched by the linker for matches to unresolved symbols. It is not an error to find a symbol in a library which matches a symbol already linked.