I’m trying to create a global array whose size is determined by an external parameter file at runtime.
I’ve seen other questions on this and tried:
int const Nt=1280;
double *Array = NULL;
Array = malloc(Nt * Nt * sizeof(double));
However, I get errors such as:
Error: Conflicting types for Array
Error: Initializer element is not constant
How can I create such a global array without needing to recompile every time I need to change its size?
Assignment is not allowed at global scope. You have to do it in a function instead.
Assuming the above 2 statements are at global scope. They are examples of initialization because the statements assign value at the declaration itself. This is allowed at global scope and the initializers can be constant values, string literals or other variables accessible at this point.
And similarly in your example
Arrayis just a declaration. Do the assignment in a function.And regarding the segmentation fault, post more code.