Re: Pointer to function

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Jun 02 1997 - 08:30:11 MEST


victor perevoztchikov wrote:
> 
>   Hello rooters,
> 
> I have a question about pointer to function.
> 
> Simple example.
> 
> #include <stdio.h>
> int ff(int (*fptr)(const char *txt),const char *txt) {
>   (*fptr)(txt);
>   return 0;
> }
> int aaa(const char *txt){ printf(txt); return 0;}
> 
> root [0] .L ff.C
> root [1] ff(aaa,"AAAA called\n");
> AAAA called
> root [2] ff(printf,"PPPP called\n");
> PPPP called
> 
> Everything OK. Somehow CINT distinguishes pointer to
> CINT function (aaa) from pointer to C++ function (printf)
> and works well.
> 
> But when ff.C linked to ROOT, then
> it still works with C++ function (printf) and does not
> work anymore with CINT function. It is clear, that C++ does not understand
> pointer to CINT function.
> 
> Questions:
> 
>  1. Is it possible to call or execute CINT function from C++ code?
>     By pointer or by name or ...
> 
>  2. Is it possible by value of pointer to understand does it pointed
>     out to C++ or to CINT function being inside C++ (not CINT) function?
> 

A complement to Masa's answer to this question.
I suggest you look in the class TF1 an example showing how to make
an interface working in the interpreted mode and compiled mode.
In one of the TF1 constructors, we make use of the CINT function
suggested by Masa: G__p2f2funcname
Look now in TF1::Eval and TF1::EvalPar to see the 3 lines of code
to return a value from this kind of function.

Rene Brun



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:19 MET