Originally Posted by
stzog
I passed them as static but i get the same error into the code not at the beginning!
Here's a test program that I wrote that allocates the same amount of memory as you are trying to allocate on the stack, assuming sizeof(int) == 4:
Code:
#include <stdio.h>
int main(void)
{
int numbers[8 * 1024 * 1024];
printf("%zu\n", sizeof(numbers));
return 0;
}
I compiled and ran this program, and ran into a segmentation fault. Here's the same program with the use of static:
Code:
#include <stdio.h>
int main(void)
{
static int numbers[8 * 1024 * 1024];
printf("%zu\n", sizeof(numbers));
return 0;
}
I compiled and ran this program, and this was the output:
Since having the variables as global variables works for you, you must have enough memory. Therefore, you must have done something wrong when changing to use static, but I cannot tell you what since you didn't show the code.
awsdert's suggestion in post #2 is also a valid strategy, except that there's more book keeping for you to do.