I am compiling my C code using the gcc compiler
My code is
main()
{
int i;
scanf("%d",&i);
int a[i];
}
... and it executes it without any warning. However, if I use:
main()
{
int i;
scanf("%d",&i);
static int a[i];
}
... I get an error message saying the size of array is not constant.
If execution of program starts at main
function it should not give such error.
and if static data is allocated first before start of main()
, how is the compiler able to generate such errors during during compile time?