How to read multiple functions in ROOT macro

Dear experts

I want to use two functions in my macro func1.cxx which likes:

type func2(arg3, arg4);
void func1(arg1, arg2){
    something;
    some = func2(arg3, arg4);
}

type func2(arg3, arg4){
    otherthings;
    return some;
}

But it doesn’t work and gives the error You are probably missing the definition of func2(arg3, arg4)
How can I fix this? I tried different ways to declare func2 inside and outside fun1 but none of them worked.


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.28.10
Platform: MacOS
Compiler: cling


Hi,

try having something like this in your func1.cxx:

type func2(arg3, arg4){
    otherthings;
    return some;
}

void func1(arg1, arg2){
    something;
    some = func2(arg1, arg2);
}

Please note that your func2 returns something but its type is void - how can that be?

This method I have already tried and didn’t work.
void because I just casually put a type for the return type, of course it’s not void in my real code…just to make the example simple

Here is the simplest working example possible:

$ cat func1.cxx
int func2(int arg3, int arg4){
    return arg3+arg4;
}

void func1(int arg1, int arg2){
    int some = func2(arg1, arg2);
    printf("some = %i\n", some);
}
$ root -l -b -q 'func1.cxx(4, 7)'

this should print

some = 11

Does this work?

After I tried this method and the method I gave above…I found both worked fine.
I have NO idea what is happening…what did I faced??? :face_with_spiral_eyes: