On May 19, 3:36 pm, The Architect <architect.mat...@gmail.comwrote:
Quote:
On May 19, 5:34 pm, Victor Bazarov <v.Abaza...@comAcast.netwrote: Quote:
The Architect wrote: Quote:
If I have the same symbol in the .data section of 2 obj
files, LD gives a multiple declaration error on linking?
Would like to know the reason for this (diab only issues a
warning)
| | |
Quote:
Quote:
I would *guess* is that LD is not designed to handle
multiple definitions of the same symbol. BTW, that is what
the C++ language Standard also requires: one and only one
definition of any symbol in your program. So, your linker
seems to be enforcing the ODR.
| |
Quote:
Quote: Quote:
Also what if the symbols were in any other section (.rdata
or .text)?
| | |
Quote:
Quote: |
The term "section" is not defined by the language Standard.
| |
Quote:
Quote: Quote:
Or which sections of obj files can be merged even if they
have overlapping symbol names?
| | |
Quote:
Quote:
That's seems like a question you need to ask in the
compiler- or platform-specific newsgroup.
| |
Quote:
I did manage to resolve the problem by making it const (the
symbol moved to the .rdata section). Was curious as to how the
linker behaved with this change.
|
Don't confuse what the compiler and linker are doing with what
you do in your C++ code to trigger this behavior. In C++, a
const variable at namespace scope has internal linkage by
default, a non-const variable at namespace scope has external
linkage by default. At the C++ level, you've changed the
linkage.
If the variable is in a header file, you've changed the number
of instances of it: with internal linkage, you have one instance
per translation unit; with external, you have one instance in
all.
As to what the compiler does with it: with external linkage, if
the declaration is a definition, the compiler generates extra
information for the linker, telling it that the symbol is
globally defined; normally, this will result in an error if
there are duplicate definitions. With internal linkage, the
compiler doesn't generate this information---as far as the
linker is concerned, the symbol doesn't exist. The segment
where the object corresponding to the symbol is irrelevant here.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34