Header file in root script

****~~~~~No data files is needed to see the following bug.

Hi ROOTers
I had the following bug in my code which took me a while to figure out since it was not obvious. The bug is observed when you changed the following line in my code attached (in the header file):

Original line:
Bug line:
“for(int i=0;i<NFILES;i++){”

I wonder if anybody else can reproduce the same error. The error statement is found in the attached file. I want to make few annotations about this bug. First the structure of this small code is simple. I have a header file and a root script.
The BUG line is in the header file. If I try to add the “int” modifier to the variable “i” in that for loop, the error comes up. However If I declared the variable in the line before like this:
“int i;
The program runs with no problem. I really would like to know the reason of this bug, but I do not think it is an obvious reason but something more in deep in the code structure.

One other thing that I notice is that if I moved all the content of the header file to the root script (merge those files together, the error will never come up). One last thing, in root, if you modified the header file, you have to reload all ROOT to download the header file from memory. If you run the script several times by making modification to the header file, ROOT will not see the modifications of the header file except only if you type “root peakfit.C” from the prompt command line.

If there any debugger in the root software that I could have used to find this error easier?

Thank you for your time,

LaBr3_data.h (1.99 KB)
peakfit.C (2.98 KB)


don’t use unnamed scripts unless you really need to. Instead write a proper C++ file, where each block of code is contained in a function. #including files inside an unnamed macro is not a good idea.

You can unload files by “.U filename.C”. Check “.?” for more help, e.g. how to use CINT as a debugger. You can also just compile your code (with proper dependency tracking for changes) by running .L / .x MyCode.C+. This also forces you to write proper C++, as your code gets compiled by your system’s compiler.

Cheers, Axel.