I have a struct named Game with an array of levels, defined like this:
typedef struct
{
Level levels[x];
} Game;
When I compile the code, if x is 1, 2 or 3, the program runs normally. If it’s any other value (4, for instance), I get a segmentation fault. I’m not accessing the array anywhere. Main is something like this at the moment (commented everything except the initialization):
int main (...)
{
Game g;
return 0;
}
Any clue of what this might be?
Thanks in advance.
How big is a
Level? Is it possible you’re overflowing your stack? Given that there’s (apparently) only ever one Game object anyway, perhaps you’d be better off using thestaticstorage class, as in:static Game g;Edit:
If you want to force allocation on the heap, I’d advise usingOops — missed it’s being tagged C, not C++.std::vector<Level> levels;rather than using pointers directly.