What is the maximum size of static array that can be declared in GCC?

前端 未结 1 1804

How its determined ? Does this depend on the compiler/Architecture/Host system ?

Example:

int array[0x8000000000000000]; 

For this

相关标签:
1条回答
  • 2020-12-15 02:10

    By static array, I assume, you mean a fixed length array (statically allocated, like int array[SIZE], not dynamically allocated). Array size limit should depend on the scope of the array declared.

    • If you have declared the array in local scope (inside some routine), size limit is determined by stack size.
    • If gcc is running on linux, the stack size is determined by some environment variable. Use ulimit -a to view and ulimit -s STACK_SIZE to modify the stack size.
    • If gcc is running on windows (like MinGW), stack size can be specified by gcc -Wl,--stack, STACK_SIZE.
    • If you have declared the array in global scope, the array is stored in DATA or BSS section (based on whether the array is initialized or uninitialized respectively). The DATA and BSS section size are determined by underlying OS.
    • If you have declared the array in static scope (like static int array[SIZE]), again, the array is stored in DATA or BSS section (based on whether the array is initialized or uninitialized respectively). The DATA and BSS section size are determined by underlying OS.
    0 讨论(0)
提交回复
热议问题