Search code examples
cstaticstructstack-overflow

why do the removal of static give ' Stack overflow' error at the beginning of my program?


I use VC2010 and when i try to debug my progam with struct replacing static i get

Unhandled exception at 0x000f18e7 in ht_array.exe: 0xC00000FD: Stack overflow.

it does it at the first line of main

#define BUCKETS 64
#define B_ENTRIES 50000

void main(int argc, char **argv)
{
static fpinfo hash_table[BUCKETS][B_ENTRIES];
static tanker_record tr[100];
....

Solution

  • Because 64 * 50000 * sizeof(fpinfo) bytes is apparently too big for your stack. With static, the variable is allocated in a different region of memory, where it does fit.