Re: return value in CINT

From: Axel Naumann <Axel.Naumann_at_cern.ch>
Date: Wed, 25 May 2011 15:57:20 +0200


Hi,

Long_t works, too. Otherwise use this approach:

Say your function returns an object of class MyClass:

  MyClass func()

Then you would invoke it like

  MyClass returnedObj;
  TString expr = TString::Format("*(MyClass*)%p = func();", (void*)&returnedObj);
  gInterpreter->ProcessLine(expr);

Cheers, Axel.

OKUMURA, Akira wrote on 05/25/2011 03:13 PM:

> Hello Axel,
> 
> Thank you. It works perfect for Int_t, but can I get other types or classes?
> 
> Regards,
> 
> --
> OKUMURA, Akira oxon@{astro.isas.jaxa.jp,stanford.edu}
> Institute of Space and Astronautical Science (ISAS/JAXA)
> Now at KIPAC/SLAC/Stanford
> Varian Physics #306, 382 Via Pueblo Mall, MC 4060
> Stanford, CA 94305-4060
> TEL 650-736-0971/FAX 650-724-5065
> Skype : okumura.akira
> 
> On 2011/05/25, at 5:49, Axel Naumann wrote:
> 

>> Hi Akira,
>>
>> use
>>
>> gROOT->LoadMacro("MyMacro.C++"); // this macro contains Int_t MyFunc()
>> Int_t n = gInterpreter->ProcessLine("MyFunc()");
>>
>> Cheers, Axel.
>>
>>
>> OKUMURA, Akira wrote on 05/25/2011 04:52 AM:
>>> Hello ROOTers,
>>>
>>> I would like to know if there is any way to get the return value of a function which is loaded via TROOT::LoadMacro in a compiled code.
>>>
>>> Below is my conceptual code to be compiled by g++.
>>>
>>> int main()
>>> {
>>> (snip)
>>> gROOT->LoadMacro("MyMacro.C++"); // this macro contains Int_t MyFunc()
>>> Int_t n = MyFunc(); // How can I do this?
>>> (snip)
>>> }
>>>
>>> I would like to use MyMacro.C as a configuration file of the main program. The algorithm inside MyFunc() changes in each MyMacro.C. For example,
>>>
>>> --- MyMacro1.C ---
>>> Int_t MyFunc()
>>> {
>>> return 1;
>>> }
>>>
>>> --- MyMacro2.C ---
>>> Int_t MyFunc()
>>> {
>>> return 2;
>>> }
>>>
>>> Regards,
>>>
>>> --
>>> OKUMURA, Akira oxon@{astro.isas.jaxa.jp,stanford.edu}
>>> Institute of Space and Astronautical Science (ISAS/JAXA)
>>> Now at KIPAC/SLAC/Stanford
>>> Varian Physics #306, 382 Via Pueblo Mall, MC 4060
>>> Stanford, CA 94305-4060
>>> TEL 650-736-0971/FAX 650-724-5065
>>> Skype : okumura.akira
>>>
>>>
>>>
>>>
>>> Regards,
>>>
>>> --
>>> OKUMURA, Akira oxon@{astro.isas.jaxa.jp,stanford.edu}
>>> Institute of Space and Astronautical Science (ISAS/JAXA)
>>> Now at KIPAC/SLAC/Stanford
>>> Varian Physics #306, 382 Via Pueblo Mall, MC 4060
>>> Stanford, CA 94305-4060
>>> TEL 650-736-0971/FAX 650-724-5065
>>> Skype : okumura.akira
>>>
>>>

>
> Received on Wed May 25 2011 - 15:57:25 CEST

This archive was generated by hypermail 2.2.0 : Wed May 25 2011 - 17:50:01 CEST