Why is this code throwing up a SIGSEGV:
int main()
{
unsigned long toshuffle[9765625];
unsigned long i;
for (i=0; i< 1000; i++)
toshuffle[i]= i;
return 0;
}
Pointers will be appreciated. (No Pun intended :))
Why is this code throwing up a SIGSEGV:
int main()
{
unsigned long toshuffle[9765625];
unsigned long i;
for (i=0; i< 1000; i++)
toshuffle[i]= i;
return 0;
}
Pointers will be appreciated. (No Pun intended :))
Probably because you can't allocate 9765625 longs on stack (what is this site called again? :)). Use malloc()
instead.
Use malloc() to get that much memory. You're overflowing the stack.
unsigned long *toshuffle = malloc(9765625 * sizeof(unsigned long));
Of course when you're done with it, you'll need to free() it.
NOTE: In C++, you need to cast the pointer to the correct type.
From the manpage
The maximum size of the process stack, in bytes. Upon reaching this limit, a SIGSEGV signal is generated. To handle this signal, a process must employ an alternate signal stack (sigaltstack(2)).