-1

I have tried to compile this C code:

#define MAX_INT 2147483647

int main()
{
   int vector[MAX_INT];
   return 0;
}

I'm using the C compilers provided by both MinGW and MSYS projects, i.e., MinGW / MSYS. MinGW compiler is "gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)", which is the most recently version and have win32 thread model, and MSYS compiler is "gcc version 3.4.4 (msys special)" with posix thread model.

That MAX_INT constant value is set in the constant "__INT_MAX__" provided by the "limits.h" header.

How can I avoid this problem and get my simplest code compiled?

Graco Babeuf
  • 3
  • 1
  • 4

1 Answers1

0

Your stack will not be that large to contain the array this is the main problem. Try setting the stack size using the following lines as suggested in Increase stack size when compiling with mingw? while compiling

gcc -Wl,--stack,N
where N is stack size. E.g. gcc -Wl,--stack,4194304

Also as mentioned in the comments you might have to compile for 64 bits and will require that much amount of RAM or possibly a large page file.