Strange problem with Form()?

file foo.C:[code]#include <TTree.h>
#include <TFile.h>

TTree *tree;

const char *getInfo()
{
return Form(“event: %lld”, tree->GetReadEntry());
}

void foo()
{
const char *name = Form(“any form %s”, “name”);
Printf(“const name = %s”, name);

TFile file = TFile::Open("$ROOTSYS/test/Event.root");
tree = (TTree
)file->Get(“T”);

for (Int_t i = 0; i < 100; i++) {
tree->GetEntry(i);
Printf("%s", getInfo());
}

Printf(“const name = %s”, name);
}[/code]and now:[quote]root [0] .x foo.C+
Info in TUnixSystem::ACLiC: creating shared library /home/mucha/./foo_C.so
const name = any form name
Warning in TClass::TClass: no dictionary for class Event is available
Warning in TClass::TClass: no dictionary for class EventHeader is available
Warning in TClass::TClass: no dictionary for class Track is available
event: 0
event: 1
event: 2
event: 3


event: 96
event: 97
event: 98
event: 99
const name = nt: 62
[/quote]const name “any form name” is changed
FC 6, gcc 4.1
on root 5.15.04 const name = nt: 62
on root 5.14.00d const name = 61
on root 4.04.02g const name = t: 61

after change type of name from char -> TString (and name -> name.Data()) all work correct.

Jan

btw, execute one more time:[quote]root [1] foo()
const name = any form name
event: 0
event: 1
event: 2
event: 3


event: 96
event: 97
event: 98
event: 99
const name = any form name[/quote] all is OK !!!

Hi,
Form() returns a pointer to a static buffer. The content of this buffer is volatile; it is only valid right after the call to Form(). In your case something between your first and last access of name changes this buffer. A common solution is to assign the returned const char* to a TString, which effectively copies Form()'s buffer.
Cheers, Axel.