Re: [CINT] Re: Embedding CINT in C++ application

From: Axel Naumann <Axel.Naumann_at_cern.ch>
Date: Thu, 6 Dec 2007 12:43:37 +0100


Hi,

On 2007-12-06 8:04, Borse, Ganesh wrote:
> (1) I tried using the Tcint class & could get the function source
> code compiled ok. But I am not able to correctly pass the parameters
> via Execute() to this function.

You should use gInterpreter (not create your own), and instantiate a TApplication object in your program's main() function.

> (2) Also, how can I get the return value of the function (say return
> value of "MyFunction") I am executing?

First of all, your output file and your function must have the same name for .x exprs.C to work. Rename your function to "int exprs(...)". You can pass values using ".x exprs.C(1, 2, "a string")".

The function's return value will be returned by gInterpreter->ProcessLine(), cast to a long. But you can e.g. pass the address of an int declared in main() to gInterpreter->ProcessLine(), and then set its value in exprs(), and read it out in main:

int val = 0;
TInterpreter::EErrorCode errInterp;
char buf[1000]; // though string stream is better sprintf(buf, ".x expr.C(0x%x)", &val); // pass the address of val to expr() gInterpreter->ProcessLine(buf);

// do error handling using errInterp

printf("expr() set val to %d\n", val);

And you have bugs in your code: operator==(char*, char*) compares the pointer values; you want a string comparison so use strcmp. And you should fclose the file before calling CINT on it or it might not be flushed yet.

Cheers, Axel. Received on Thu Dec 06 2007 - 12:43:59 CET

This archive was generated by hypermail 2.2.0 : Thu Dec 06 2007 - 17:50:02 CET