Topic: Unique names (Was: lambda functions proposal)
Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/11/29 Raw View
James.Kanze@dresdner-bank.de wrote:
> Just curious, but how do implementors generate a name guaranteed to
> be unique. Within a compilation unit, they just number, of course.
> But between compilation units. You can't use the file name; I can
> still remember the problems that caused in CFront (which used the
> file name to generate the names of the functions to construct and
> destroy local variables).
You mean globals and static variables, don't you ?
> You can't really use the full path; I
> can build a library in my home directory on one machine, and use
> it with code developed in my home directory ("/home/kanze" in both
> cases) on another, so the problem is the same as filenames. You
> can't use the machine name, since this is only guaranteed unique
> within the same domain. You can't use a time stamp, since with
> many people working on the same project. You can't even really
> use the fully qualified domaine -- most PC users don't have one.
>
> So what do they do?
I run some tests with egcs/g++ and I found that it tries hard
to generate different names for different types (that is, I
haven't been able to define two types with the same name).
For types locals to one TU (with or w/o linkage), it uses
something like TU_ID ## type_name ## scope_ID.
TU_ID is the signature of the first non inline extern
function definition of the TU.
scope_ID is local to the TU.
You can define types with no functions at all in
the TU:
// foo.cc
namespace {
struct foo {};
}
// end foo.cc
but you can't really do anything with them, so you
can just forget them.
You can hardly use anonymous namespaces members in
inline functions because you wouldn't be able to
duplicate the definition of the function in any other TU.
Note: more recent tests indicate that it uses the file
name for the TU_ID, so I guess it's a recent change in
egcs (using:
Reading specs from
/usr/local/util/packages/egcs-050798/lib/gcc-lib/sparc-sun-solaris2.5/egcs-2.91.45/specs
gcc version egcs-2.91.45 19980704 (gcc2 ss-980609 experimental)
).
More precisely, egcs uses the local path to the files: foo.cc,
bar/foobar.cc, ect) but not /users/bonnard/C++/foo.cc
for example.
--
Valentin Bonnard mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://pages.pratique.fr/~bonnardv/
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]