I'm really new to C and something is bugging me...
I declared a typedef:
typedef struct{
double
real,
img;
}complex;
And, inside a function, I declared the following array:
complex system[MAX_NODES+1][MAX_NODES+2];
The first thing the function does with the elements of this array is initializing them, but the application would compile and crash during runtime, UNLESS another array with the same dimensions and type was also declared (even though it wasn't used):
complex system1[MAX_NODES+1][MAX_NODES+2],
complex system[MAX_NODES+1][MAX_NODES+2];
This led me to believe it was a memory problem, and maybe the first system was allocating the memory that was needed... Is that the case? If so, why?
MAX_NODES is a constant set to 300, so I thought the array declaration was already allocating the memory... Should I actually use malloc?
Anyways, declaring that system as static seems to solve the problem:
static complex system[MAX_NODES+1][MAX_NODES+2];
I just don't know why... I know a static variable inside a function makes that variable hold its value in subsequent function calls, but how is that related to memory or whatever this problem is? Any tips?
Thanks a lot in advance.