* Q: CXX Template instantiation mechanisms...
@ 1998-04-24 4:00 Marcin Kasperski
0 siblings, 0 replies; only message in thread
From: Marcin Kasperski @ 1998-04-24 4:00 UTC (permalink / raw)
Digital CXX has fairly nice template instantiation mechanism. In a few
words, it put all needed template instantiations into subdir
cxx_repository, and reuses them when needed. But sometimes it refuses to
make global instantiation and instead of it add instantiation into code
of module which needed it. Then, if two different modules uses this
instantiation, during linking I get name conflict. The situation is
described in a piece of Digital CXX documentation which I'd like to
quote:
> In some cases, DIGITAL C++ is unable to write template instantiations into the repository.
When a template instantiation references a variable or function that is
local to the source file,
that variable or function is generated as part of the user's object file
instead of in the
repository. It is an error to link an application that has differing
instantiations of the same
template, which would be the case if a template that referenced local
variables were instantiated
in two or more different source files. An attempt to do so is diagnosed
at link time with a
multiply defined error.
The description above is rather short...
I found myself to achieve such an error after every greater code change.
I located, that problem can be for instance caused by static variable
placed in header file, exactly it happens when we have:
---- header.h
...
static char* = "XXX";
...
--- templ.h
template <class X> void swap (X& a, X& b);
--- templ.cc
template <class X> void swap (X& a, X& b) { X tmp = a; a = b; b = tmp; }
--- file1.cc
#include "header.h"
#include "templ.h"
...
int a,b;
swap (a,b);
--- file2.cc
#include "header.h"
#include "templ.h"
...
int a,b;
swap (a,b);
----
cxx file1.cc file2.cc
plik2.o: swap(int,int) multiply defined
This example is real, some library I use places in headers lines like
static char h_...[]="@(#)...";
I found also, that problem happens when header needed to implement
template is not included to template implementation file but into file
which instantiates template. But tracing that is hard.
I'd be grateful for:
- any other scenarios which could cause such a behaviour
- any advice/link to tool/idea of application/... of how to atomatically
trace such a problems (i.e get to know why this and this template is
being instantiated locally)
- any more or less general remarks about the situation
Marcin Kasperski
marcink@crt.tpsa.pl
PS. Please, CC answers to me... I use mail internet/intranet gateway. I
haven't such for news...
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1998-04-24 4:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-04-24 4:00 Q: CXX Template instantiation mechanisms Marcin Kasperski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox