array bound is not an integer constant

Hi

1)
const int array_const []= {1,2,3,4,5,6}; //ok
float float_array[array_const[2]]; // Throws an error "array bound is not an
int main() {} integer constant"


2)
int char_array = 126; //ok
int glob_array[char_array]; // Throws an error "array bound is not an integer
int main() {} constant"

Above pice of the code (1 & 2) throws an error "array bound is not an integer constant" From above error I understood that compiler not reading content of the storage at compile time.

I am not understand why its not reading. Please can someone explain me in details ?

---------------------------------------------

const int char_array = 126; //ok
int glob_array[char_array]; // ok
int main() {}

Above pice of the code work fine without an issue.

Also let me know In C why below statement throws "variably modified store_char at file scope" error

#include<stdio.h>

const int maxarray=255;
char store_char[maxarray];
int main() {
}


1) You have a non-const array of const integers there, so you can't use the [] and expect that to come out at compile time.

2) You are correct. Since the array is allocated at compile time, and the variable is only initialized when you run the program, you can't do that.

3) No idea here...
Thanks for Update

Is there any links which tells what are all the things happing during compile time and how object file creates.

Actally I want to know why array is allocated at compile time and why variable get initialized during run time
Topic archived. No new replies allowed.