Segfaults with script

I believe I have debuged all errors in my script with brun’s help. But I am now getting a segfault (no other compile errors) I’m not sure how to debug this.

Any idea what i could be doing wrong? Note: I’m not a very good C++ programer. This occurs even if I remove all calls to the readascii
function, so the problem seems to be fundamental.

Even assistance of how to debug segfaults via root would help.



root [1] .L mchistnew.c+
Info in TUnixSystem::ACLiC: creating shared library
root [2] main();
Error in TApplication::TApplication: only one instance of TApplication allowed
Note: File “iostream” already loaded
Note: File “_string” already loaded
Note: File “vector” already loaded
Note: File “pair” already loaded
Note: File “RtypesCint.h” already loaded
root [0]
*** Break *** segmentation violation
Generating stack trace…
0x080488dd in main + 0x71 from /home/morris/root/bin/root.exe
0x05d17c14 in from /home/morris/Banalysis/./
0x001449e6 in G__ExceptionWrapper + 0x42 from /home/morris/root/lib/
0x001c6a6f in G__call_cppfunc + 0x2a7 from /home/morris/root/lib/
0x001b5c4e in G__interpret_func + 0x790 from /home/morris/root/lib/
0x001a5049 in G__getfunction + 0x1aa5 from /home/morris/root/lib/
0x0019b9b5 in G__getitem + 0x5c7 from /home/morris/root/lib/
0x0019a5aa in G__getexpr + 0x884c from /home/morris/root/lib/
0x001ddd6e in G__exec_function + 0x1d8 from /home/morris/root/lib/
0x001e4d94 in G__exec_statement + 0x254a from /home/morris/root/lib/
0x00181a76 in G__exec_tempfile_core + 0x2ee from /home/morris/root/lib/
0x00181c68 in G__exec_tempfile_fp + 0x22 from /home/morris/root/lib/
0x001ed349 in G__process_cmd + 0x4767 from /home/morris/root/lib/
0x00881e33 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) + 0xa9 from /home/morris/root/lib/
0x007cd19c in TApplication::ProcessLine(char const*, bool, int*) + 0x61e from /home/morris/root/lib/
0x004f9bdb in TRint::HandleTermInput() + 0x1dd from /home/morris/root/lib/
0x004f88ca in TTermInputHandler::Notify() + 0x24 from /home/morris/root/lib/
0x004fa490 in TTermInputHandler::ReadNotify() + 0x12 from /home/morris/root/lib/
0x00905532 in TUnixSystem::CheckDescriptors() + 0x144 from /home/morris/root/lib/
0x00904420 in TUnixSystem::DispatchOneEvent(bool) + 0x152 from /home/morris/root/lib/
0x00841574 in TSystem::InnerLoop() + 0x18 from /home/morris/root/lib/
0x00841519 in TSystem::Run() + 0x6f from /home/morris/root/lib/
0x007cdc7c in TApplication::Run(bool) + 0x32 from /home/morris/root/lib/
0x004f966c in TRint::Run(bool) + 0x3ea from /home/morris/root/lib/
0x080488dd in main + 0x71 from /home/morris/root/bin/root.exe
0x0247479d in __libc_start_main + 0xed from /lib/tls/
0x080487e1 in _Unwind_Resume + 0x31 from /home/morris/root/bin/root.exe
Root >
b0_nuovo_small.c (56.6 KB)
mchistnew.c (14.8 KB)

Hi James,

when it comes to main() functions the old rule “though shalt not have any god beside me” holds. One main() per executable, not more. And you tried to smuggle another one into root’s executable.

Simply rename your main to e.g. MyMain and it’ll work (it does for me).

You have two very serious problems in your code:
At line 406, your statement
int nmnu = nmnu+1;
but nmnu is not initialized. My guess is that you should have a statement outside the loop
int nmnu = 0;
and replace line 406 by

then at line 475 your statement
if (cut9) nplep = nplep+1;
has cut9 undefined


Thank you both very much, I would have never found those.