Re:variable length array inside loop

=?ISO-2022-JP?B?GyRCOGVGIyEhQDU8IxsoQg==?= (MXJ02154@niftyserve.or.jp)
Thu, 17 Jul 1997 20:05:00 +0900


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??????