I am writing some C code here, and I came across a problem:
I have an array of my custom type. I want to put a size for this array:
typedef struct reg Reg;
Reg myArray[958279];
When I run my program has a segmentation fault.
Then I tried using malloc, which allocates storage space dynamically, and to my surprise it worked:
Reg *myArray = (Reg*)malloc(sizeof(Reg)*958279);
So I assumed there must be some size restriction for array declaration of a static form.
Is there any reference to this fact somewhere? Or am I completely wrong about the my questions?
The array in your first piece of code is, presumably, being allocated on the stack and does not fit. The stack typically has a fixed size and you must not allocate huge objects on the stack. The solution, as you have discovered, is to allocate from the heap.