ROOT Version: 6.36.06 Platform: Mac OSX Compiler: Not Provided
I am getting different results depending on whether I load some code that contains a a function or just simply code to be executed. Here is the file
int test() { // comment out this line for second example
double xLo = 0.0;
double xHi = 1.0;
int nBins=10;
double delta = (xHi - xLo) / nBins;
for (int iBin = 0; iBin < nBins; iBin++) {
double x = iBin * delta;
std::cout << iBin << " " << x << " " << delta << " " << iBin * delta << std::endl;
}
return 1;
} //comment out this line for second example
loading and executing this code gives the expected result:
However, if I comment out the two lines declaring and ending the function I get a different result in which either integer arithmetic is done instead of double:
------------------------------------------------------------------
| Welcome to ROOT 6.36.04 https://root.cern |
| (c) 1995-2025, The ROOT Team; conception: R. Brun, F. Rademakers |
| Built for macosxarm64 on Sep 17 2025, 18:52:01 |
| From tags/6-36-04@6-36-04 |
| With Apple clang version 17.0.0 (clang-1700.3.19.1) |
| Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q' |
------------------------------------------------------------------
@bellenot On a Linux (x86_64) machine, when trying the test.cc example with “commented lines”, ROOT 6.36.04 and 6.34.10 show the same problem as reported. ROOT 6.32.18 dies with a segmentation violation. ROOT 6.30.08 and older (e.g., 6.28.12) report and “error: expected unqualified-id” (for the “for” loop).
@preimer It seems to me that you are trying to create/use a so-called “unnamed macro”.
In this case, you need to “encapsulate” the whole source code in a {...} block.
So, in your test.cc example, replace the line: int test() {
With a simple line: {
I also recall that many older ROOT versions required the very first line of an “unnamed macro” file to be the “{” line (so, do not add any “comment lines”, or any preprocessor directives, right in the beginning of your macro file; add them after the initial “{” line, if needed).
Be also aware that there are known problems with “unnamed macros” in ROOT 6, e.g., the “return” from it is broken (reported in 2018, still unsolved in 2025).