Variable length array

Gabriel Paubert paubert@iram.es
Mon Aug 3 10:47:00 GMT 1998


On Mon, 3 Aug 1998, Luigi Pilo wrote:

> Trying to compile the following with gcc version 2.7.2.1 or egcs-1.0.3
> 
> int main()
> {
>    int dim; 
>    dim = 3;  
>    
>    /* GNU variable length array */
>    int gnu_array[dim]; 
>    return 0;
> } 
> 
> I get:
> test.c: In function `main':
> test.c:7: parse error before `int' .
> 
> The problem disappear replacing "int dim; dim = 3;" by
> "int dim = 3;"  .
> 

That's normal C syntax. First declarations than statements. You have to
start a block delimited with braces if you want  to declare variables. The
common trick is to write in this case:

int main()
{
   int dim; 
   dim = 3;  
   
   /* GNU variable length array */
   do {
     int gnu_array[dim];
     ...
   } while (0); 
   return 0;
} 

	Gabriel.




More information about the Gcc-bugs mailing list