RE: [ROOT] _R__UNIQUE is not so unique

From: Philippe Canal (pcanal@fnal.gov)
Date: Wed Sep 18 2002 - 00:25:41 MEST


Hi Roger,

The reason for the almost unique identifier is that
  1. we need a way to force execution of some code at library
        load time and we use a static global variable
        to implement this
  2. we do not know how to produce using a CPP macro
        a really unique identifier (does anybody know
	  how to do it?)

In ROOT 3.03/07 the only purpose of ClassImp is to register the location of
the implementation file of the class.  If you do NOT use THtml of your
classes, you can just remove the macro from your file.

For regular class, we also provided a replacement to ClassImp(classname):
ClassImpUnique(className,Y) where Y can be anything provided by the user to
make the identifier unique (it becomes R_dummyholderUSERPROVIDED66).

> ... separete linkdef ... However my guess would be that this could cause
> problems at link time with the symbols clashing then.

It would not be a problem since the variable is declared static and thus is
only seen in the current compilation unit.

Does anybody know how we could implement this differently?  (It has to be a
CPP macro since the whole purpose is to acquire the __FILE__ and __LINE__ in
the implementation file.

Cheers,
Philippe

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Roger Moore
Sent: Tuesday, September 17, 2002 1:46 PM
To: roottalk@pcroot.cern.ch
Subject: [ROOT] _R__UNIQUE is not so unique


I recently upgraded from ROOT 3.03/05 tp 3.03/07 and suddenly found that
code generated by rootcint would no longer compile giving errors of the
ilk:

"GtCut.hpp", line 166: error: variable "R__dummyholder166" has already been
          defined

Having a look at the ClassImpT macro and tracing it back up the macro tree
I found that it essentially instantiates a global symbol using the macro:

	_R__UNIQUE(R__dummyholder)

which relies on the macro _R__UNIQUE (in RConfig.h) to generate a unique
symbol each time. However all it does is tack the current line number onto
the given argument which, if you ever have more than one file, is not
unique.

Other than adding blank lines here and there throughout the code (to
ensure that no two ClassImpT calls are on the same line!) I see no way to
avoid this. I thought about moving from a system of grouped LinkDef.h
files (where I have one LinkDef.h per directory) to separate linkdef
files for each class. However my guess would be that this could cause
problems at link time with the symbols clashing then.

Could this please be fixed? If it remains as it is then ROOT code becomes
dependent on the line number where you write it which I don't think is a
desirable feature.

Thanks,

Roger



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:10 MET