Filling tree as in the documentation

I’m creating a tree as in the documentation (pag.199)

    TFile f("data.root", "recreate");
    TTree tree("tree", "tree");
    Float_t x = 10.;
    tree.Branch("x", &x, "x/F");
    const int N = 10;
    for (int i=0; i!=N; ++i)
    {
	tree.Fill();
    }
    tree.Write();

it works, but when I exit from ROOT:


root [1] .q

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x0000003e15ebb02e in waitpid () from /lib64/libc.so.6
#1  0x0000003e15e4212e in do_system () from /lib64/libc.so.6
#2  0x0000003467a483bd in TUnixSystem::StackTrace() () from /usr/lib64/root/libCore.so.5.30
#3  0x0000003467a4ac83 in TUnixSystem::DispatchSignals(ESignals) () from /usr/lib64/root/libCore.so.5.30
#4  <signal handler called>
#5  0x0000000001eca7e0 in ?? ()
#6  0x000000346830d738 in ?? () from /usr/lib64/root/libTree.so
#7  0x0000003466f05a8b in Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) () from /usr/lib64/root/libCint.so.5.30
#8  0x0000003466f07c21 in G__execute_call () from /usr/lib64/root/libCint.so.5.30
#9  0x0000003466f0800e in G__call_cppfunc () from /usr/lib64/root/libCint.so.5.30
#10 0x0000003466eeeda7 in G__interpret_func () from /usr/lib64/root/libCint.so.5.30
#11 0x0000003466e8a5a6 in G__getfunction () from /usr/lib64/root/libCint.so.5.30
#12 0x0000003466edc237 in G__destroy_upto () from /usr/lib64/root/libCint.so.5.30
#13 0x0000003466edc82f in G__scratch_globals_upto () from /usr/lib64/root/libCint.so.5.30
#14 0x0000003467a10818 in TCint::ResetGlobals() () from /usr/lib64/root/libCore.so.5.30
#15 0x0000003467a446aa in TUnixSystem::Exit(int, bool) () from /usr/lib64/root/libCore.so.5.30
#16 0x00000034679ec119 in TApplication::ProcessLine(char const*, bool, int*) () from /usr/lib64/root/libCore.so.5.30
#17 0x000000346c41d5b9 in TRint::HandleTermInput() () from /usr/lib64/root/libRint.so.5.30
#18 0x0000003467a49c9c in TUnixSystem::CheckDescriptors() () from /usr/lib64/root/libCore.so.5.30
#19 0x0000003467a4b3f6 in TUnixSystem::DispatchOneEvent(bool) () from /usr/lib64/root/libCore.so.5.30
#20 0x00000034679dc546 in TSystem::InnerLoop() () from /usr/lib64/root/libCore.so.5.30
#21 0x00000034679de1e4 in TSystem::Run() () from /usr/lib64/root/libCore.so.5.30
#22 0x00000034679ea4af in TApplication::Run(bool) () from /usr/lib64/root/libCore.so.5.30
#23 0x000000346c41dfc2 in TRint::Run(bool) () from /usr/lib64/root/libRint.so.5.30
#24 0x0000000000400fac in main ()
===========================================================

root 5.30/03

mmm, the crash is only when my code is

code.C:

{
...
}

but it works (without crash) if my code is

code(){
...
}

Yes, this is a known problem with CINT handling of stack defined TFile object. When declaring them in the global CINT scope (and/or in { … } ) make to declare them as pointer.

Cheers,
Philippe.