Error: Redefinition of default argument

Hi there,

Let’s say I have 2 files:

  • mrf.C, the file in which all my personal ROOT functions lie and I always compile

#include <TString.h> void MRF_dummy ( TString location, TString message, TString type="-1" ) { return ; }

  • ztest.c, a basic program using mrf.C functions and that I’d like to execute OR compile

#include "mrf.C" void ztest () { //gROOT->ProcessLine(".L mrf.C+") ; return ; }
If I just execute ztest.c

root [] .L mrf.C+ root [] .x ztest.c I get the following error message:

Error: Redefinition of default argument mrf.C:3: *** Interpreter error recovered *** This is due to the fact the last argument of MRF_dummy (namely “type”) is given a default value. If I don’t set anything, no prob.
Of course, no prob at all in compiled mode

root [] .L mrf.C+ root [] .L ztest.c+ root [] ztest()
What do I miss?

in ztest.C remove the first line #include “mrf.C”, otherwise you will compile mrf.C too and then try to recompile again and load it.


Thanks René.
But then I cannot compile it anymore.
The following works in any cases without loading mrf.C:

  • mrf.C[code]#include <TROOT.h>
    #include <TString.h>

void MRF_dummy ( TString location, TString message, TString type="-1" )
printf ("\nlocation=%s / message=%s / type=%s\n",location.Data(),message.Data(),type.Data()) ;
return ;

  • ztest.c[code]#if !defined(CINT) || defined(MAKECINT)
    #include “mrf.C”

void ztest ( TString str=“hello” )
gROOT->ProcessLine(".L mrf.C+") ;
MRF_dummy (“ztest”, str) ;
return ;

Execution:root [] .x ztest.c
Compilation:root [] .L ztest.c+
Thanks for commenting if it sounds clumsy.
Cheers, Z


this is a basic C++ question, not really ROOT related. Why don’t you simply declare the function in ztest.c, the way you would usually do it in headers, as in

void MRF_dummy ( TString location, TString message, TString type /*= "-1"*/ );

void ztest ( TString str="hello" )
  gROOT->ProcessLine(".L mrf.C+") ;
  MRF_dummy ("ztest", str) ;
  return ;

That works both compiled and interpreted. Also, files ending on “.c” signal to the compiler that it’s a C file, though in your case it’s a C++ file. So please use C or cxx or cpp or cc; see the gcc documentation.

Cheers, Axel.

Thanks Axel.
Maybe should I explain how I work with ROOT.
Each time I create a new piece of code (let’s say ztest.c), I link (ln -s) three files in the current directory: mfr.C (standing for MyRootFunctions), rootlogon.C and rootalias.C.
mrf.C is my secret continuously growing toolbox which is now about 7.5 kLOC and contains more than 300 functions I use to code faster. It mainly contains system, math and graphical functions I use as a complement to ROOT, e.g. to get a uniformly log-distributed xbins or to move the statbox with a one-line command:

void MRF_setStatsPosition (TH1 *histo, Int_t color, Double_t x1, Double_t y1, Double_t x2, Double_t y2, Double_t textSize=-1., Bool_t fill=kFALSE, Bool_t setoptfit=kFALSE, Int_t borderSize=1) { TPaveStats *statbox = (TPaveStats*) histo->GetListOfFunctions()->FindObject("stats") ; if ( !statbox ) { fprintf (stderr, "\n\n!!! Error in 'MRF_setStatsPosition': histogram '%s' does not have a statbox. \n\n",histo->GetName()) ; getchar() ; exit(1) ; } else { statbox->SetTextColor(color) ; statbox->SetLineColor(color) ; statbox->SetShadowColor(kWhite) ; statbox->SetX1NDC(x1) ; statbox->SetY1NDC(y1) ; statbox->SetX2NDC(x2) ; statbox->SetY2NDC(y2) ; if ( textSize != -1. ) { statbox->SetTextSize(textSize) ; } statbox->SetShadowColor(kWhite) ; statbox->SetBorderSize(borderSize) ; if ( fill ) { statbox->SetFillStyle(1) ; statbox->SetFillColor(kWhite) ; } else { statbox->SetFillStyle(0) ; } if ( !setoptfit ) { statbox->SetOptFit(0) ; } } return ; }
So declaring all the functions I use as a preamble in ztest.c looks like a waste of time.
One of the major drawback of my technique is that when I compile my small ztest.c, I end up (after several (tens of) seconds!) with a MB file :confused:

What do you reckon? Does my technique make sense? How could I improve it?



let me translate what you said: you have your own library. It’s extremely common to have header files with libraries - it’s the only way to consistently be able to call the functions in libraries. And that’s exactly what you are missing: you need to have a mfr.h that you can include in all your code using the functions from mfr.C. You have rediscovered headers :wink:

Cheers, Axel.