"variable-size type declared" error for const sized array
Bahadir Balban
krupiyer@gmail.com
Thu Sep 1 12:29:00 GMT 2005
>Hi Bahadir,
>
>It worked for me.
>
>Could you provide an example that illustrates the problem >you are
experiencing?
>
>Is it in C or C++ or some other language?
>
>What version of GCC you are using?
>
>What is your command line to compile your code?
>
>Thanks,
>--Eljay
Hi Eljay,
I see that it works when the array is a local variable. But in the
following piece of code:
#include <stdio.h>
// const int const_asize = 10;
#define define_asize = 10;
int array[define_asize] = {1,2,3,4,5,6,7,8,9,0};
int main(int argc, char * argv[])
{
return 0;
}
With a define it compiles with no errors, however if you replace it
with the constant variable, I get the following error:
"error: variable-size type declared outside of any function"
"error: variable-sized object may not be initialized"
This is on gcc version 3.3.5 compiling with the following:
gcc -o consttest main.c
adding a -std=gnu99 does not make any difference.
My opinion is that it is not the best behaviour to differentiate
between a literal and a const int when they're declared global, but
make no distinction when they're local. What do you think?
Thanks,
Bahadir
More information about the Gcc-help
mailing list