RE:#define problem.

From: Masaharu Goto (MXJ02154@nifty.ne.jp)
Date: Sat Aug 08 1998 - 09:34:00 MEST


Tomasz,

Cint has limitation in #define usage. Especially from the interactive interfac
e,you can use #define is such ways.  It is recommended to use #define only for
#ifdef , #ifndef switch and simple constant value definition.
This is a fundamental limitation which can not be changed easily.

>root [1] TFile *ff= new TFile("c6d-all-sm.root");
>root [2] TNtuple *ntp = (TNtuple*) ff->Get("ntuple");
>root [3] #define tr ntp
>root [4] tr->Draw("LC:Xnm")
>Error: non class,struct,union object tr used with . or -> FILE:/tmp/21737eaa
>LINE:1
>*** Interpreter error recovered ***

Use reference type variable instead.

 root[3] TNtuple*& tr = ntp           <<<<< instead of #define
 root[4] tr->Draw("LC:Xnm")

>Another examples:
>
>root [7] #define asde(x) (2*x-13/x)
>root [8] asde(12)
>Error: Unexpected EOF G__fgetstream():2 FILE:/tmp/21737gaa LINE:1
>Advice: You may need to use +P or -p option
>
>Another one:
>
>root [0] #define asde(x) (2*x-13/x)
>root [1] printf("%d\n",asde(12));
>Warning: sde(12) Missing ';' FILE:tmpfile LINE:4
>Error: No symbol ) in current scope  FILE:tmpfile LINE:4
>*** Interpreter error recovered ***

Do not do this. Write a function and load it using .L command.

// asde.h
template<class T> T asde(T x) { return(2*x-13/x); }

  root[7] .L asde.h
  root[8] asde(12)

Masaharu Goto



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:36 MET