Function names, clashing, scope and context

Hi Rooters,

I’d like to ask a general question regarding function names and how to handle them (in the context of possibly other unkown usages) in a way to avoid name clashes.

For concreteness, let’s use TF1, but I think the issues goes beyond that particular class. Let’s say also that my main concern is to work within a compiled application (i.e. outside CINT). Say I have common C/C++ function where I want to do something like

TF1 fa1(“fa1_name”,“sin(x)/x”,0,10);
// use fa1 only locally, without taking references,
// pointers or anything like that.

Strictly speaking I don’t care about “fa1_name”, 'cause I will just use fa1 to call some method and that’s all, end of my C/C++ function and of the scope of fa1. I think, Root does care about the name: so I have to put something, I understand: How to do that? I mean, how to avoid using a name previously used by someone else (or even myself!) in another part of the program. If there’s a name collision, my newly created object (tough being on the stack) will take the place of the former in Root’s internal bookkeeping structures.

What’s the recommended way to follow in the cases?

Cheers, and thanks a lot for your help and clarification of this issue.

Name of objects like in TF1 is an essential ingredient to find out any function later on.
If you simply use a TF1 locally you can use any name of your choice that is unique (put for example the name of the function where you call TF1).

Rene

Hi Rene, thanks for the answer.

That is what I’m currently doing, using the fully qualified name of the function (namespace, class, and function name itself).

It seemed the best choice and enough, tough the uniqueness cannot be guaranteed, at least against purposedly chosen names (or really bad luck).

I wanted to be sure that the name is mandatory (as it seemed, and you now confirm) and that there was no “unnamed” alternative to be used.

Cheers, and thanks a lot again for your clarification.

One more little thing to add: The name of the function is not enough in case of recursion (be it direct or indirect) and in the case of multiple threads of execution, in this last case I’m not sure what’s ROOT’s policy about bookkeeping.

Cheers, and thanks a lot for the given help.

Hi,

You can check for already used name viagROOT->GetListOfFunctions()->FindObject(proposed_name);

Philippe.