James Kanze
10/1/2008 9:37:00 AM
On Sep 30, 8:06 pm, ebony.s...@gmail.com wrote:
> On Sep 29, 4:44 pm, James Kanze <james.ka...@gmail.com> wrote:
> > On Sep 29, 1:17 pm, Pete Becker <p...@versatilecoding.com> wrote:
> > > On 2008-09-29 06:01:07 -0400, ebony.s...@gmail.com said:
> > > > I encountered a simple but IMO important problem about the
> > > > C++ linkage model and One Definition Rule. Why the following
> > > > code link?
> > > > file1.cpp
> > > > int x;
> > > > file2.cpp
> > > > double x;
> > > > x was defined in two different translation units with
> > > > different types. It breaks the ODR.
> > > The language definition doesn't require compilers to
> > > diagnose violations of the ODR. Code like this has
> > > undefined behavior. As a practical matter, recognizing
> > > errors like this is expensive, given C++'s separate
> > > compilation model.
> > And the relatively low quality of most linkers. It wouldn't
> > be very hard to implement, if the linker supported it. For
> > historical reasons, most linkers don't.
> Thank you for your answer. AFAIR, Stroustrup mentioned the poor
> quality of linkers in 1st edition
> of his book.
Yes. C++ was originally designed to use existing linkers, with
a minimum of additional baggage. (There was, IIRC, always a
"pre-linker", which generated the code for dynamic
initialization. But that was it.)
Today, of course, templates require a lot more support, and much
of it could be used to allow greater freedom elsewhere as well.
> Where can I find, C++ Linker specific information?
To tell the truth, I don't know. Linkers seem to be the poor
relative in the language translation area: you'll find all sorts
of information concerning compiler theory and the like, but very
little about linkers.
I think the question has been raised once or twice in
comp.compilers; you might try there. (Not because the question
is off subject here, but because that's where the people who
actually work on these things hang out.)
--
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