Re: [ROOT] Variable array dimension

From: Victor Perevoztchikov (perev@bnl.gov)
Date: Sun Apr 08 2001 - 01:47:25 MEST


Hi Christian,
your code is correct for gcc. For other compilers it will not be compiled.
Victor

cstrato@EUnet.at wrote:
> 
> Dear Rooters
> 
> In the CINT documentation there is the following statement:
>  + constness of array dimension
>    Variable dimension is not allowed in C/C++. Cint has special
> capability to
>   allow it only in interactive command and '{ ... }' style macro.
> 
>      void f() {
>        int n=5;
>        float a[n]; // this is error now
>      }
> 
> Now I have the following compiled code which seems to work very well:
> void MyClass::Calculate(Int_t size)   // size >= 1000
> {
>    Int_t len[size];
>    for (i=0; i< size; i++) {
>       len[i] = a_number;
>    }//for_i
> }
> 
> Now my questions:
> 1, Is my code correct or do I have to use ?Int_t *len = new
> Int_t[size]??
> 2, If this is an error, why can I compile the code without problems?
> 
> My system: root3.00/06 on LinuxPPC
> 
> Thank you in advance
> Best regards
> Christian
> 
> ----------------------------------
> C.h.r.i.s.t.i.a.n  S.t.r.a.t.o.w.a
> V.i.e.n.n.a.  A.U.S.T.R.I.A
> e-mail: cstrato@EUnet.at

-- 
Victor M. Perevoztchikov   perev@bnl.gov  perev@vxcern.cern.ch       
Brookhaven National Laboratory MS 510A PO Box 5000 Upton NY 11973-5000
tel office : 631-344-7894; fax 631-344-4206; home 631-345-2690



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:41 MET