Re: [ROOT] scope of local variables in cint

From: Masaharu Goto (MXJ02154@nifty.ne.jp)
Date: Sat May 03 2003 - 04:00:14 MEST


Hello Walter,

Thank you for your e-mail. I am happy to answer your question.

It is a limitation of Cint that it has only one scope inside a function.
If you declare a variable with particular name, you can not
re-declare it as different type in same function.

  void f() {
     int m, k;
     {
        int k;         // redeclaration with same type, ignored
        double m; // << this becomes an error
     }
  }

Please use different name for them.  This comes from intrinsic
part of Cint implementation, hence, it is not easy to change this
behavior.  I'd appreciate your understanding.

Thank you
Masa Goto



----- Original Message -----
From: "Walter F.J. Mueller" <W.F.J.Mueller@gsi.de>
To: <roottalk@pcroot.cern.ch>
Sent: Friday, May 02, 2003 10:23 PM
Subject: [ROOT] scope of local variables in cint


> Dear ROOTers,
>
> the attached little script "demo.C" works fine when executed
> with ACLiC. However, when just interpreted with CINT I get
> the error message
>
>    Processing demo.C...
>    Error: p already declared as different type FILE:demo.C LINE:17
>    *** Interpreter error recovered ***
>
> So CINT seems to have a problem handling the scope of the
> variables correctly. It seems that somehow the type of the first
> declaration of 'p' is memorized and the interpreter chokes when a
> variable with this name is declared a second time.
>
> Is this a restriction in CINT ?
>
>
> Cheers, Walter
>
> --
> Walter F.J. Mueller   Mail:  W.F.J.Mueller@gsi.de
> GSI,  Abteilung KP3   Phone: +49-6159-71-2766
> D-64291 Darmstadt     FAX:   +49-6159-71-2989
> WWW:   http://www-kp3.gsi.de/www/kp3/people/mueller.html
>


----------------------------------------------------------------------------
----


> #ifndef __CINT__
> #include "TCanvas.h"
> #include "TLine.h"
> #include "TBox.h"
> #endif
>
> void demo()
> {
>   TCanvas* c1 = new TCanvas("c1", "" , 20,20,700,900);
>
>   if (1) {
>     TLine* p = new TLine(0.,0.,1.,1.);
>     p->Draw();
>   }
>
>   if (1) {
>     TBox* p = new TBox(0.4,0.4,0.6,0.6);
>     p->Draw();
>   }
>
>   c1->Update();
> }
>



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:11 MET