Re:variable length array inside loop

From: $B8eF#!!@5<#(
Date: Thu Jul 17 1997 - 13:05:00 MEST


Dear V.Ninov,

Concerned about the report below,

 Declaring an array with variable index is not a valid C/C++
statement. If this were a compiler, it caused a compile error. 
Because of dynamic nature, CINT allows such declaration, however, 
not kind enough to allow changing array index in a loop. Please
use following notation which is valid C/C++.

 for(...) {
   unsigned char *buf = new@handshake[1]];

   delete[] buf;
 }

Masaharu Goto

>   for (int i = 1; 1;i++)
>   {
>      long zeros[4] = {0,0,0,0};
>      unsigned char buf[handshake[1]];
>      printf("Buffer Size %u\n",sizeof(buf));
>      printf("Requesting stream number %d\n",i);
>      if (s->SendRaw(zeros,3*sizeof(long),0) < 0)
>         printf("Error in sending request\n");
>      for (int k = 1; k <= handshake[2]; k++)
>        {
>        if (s->RecvRaw(buf,handshake[1],0) < 0)
>          break;
>        printf("Buffer %d  received\n",k);
>        }
>}
>If one puts the declaration 
>      unsigned char buf[handshake[1]];
>inside the inner loop, the interpreter is complaining about 
>index out of range in  second itteration of the outer loop!
>Why??????



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