Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

Example:

int array[0x8000000000000000]; 

For this line in a x86_64 bit system GCC outputs:

Error "size of array 'array' is too large".
like image 695
ted Avatar asked Aug 22 '13 04:08

ted


People also ask

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

An array can have a maximum of eight dimensions. You declared an array whose total size is greater than the maximum allowable size. The maximum allowable array size is 65,536 bytes (64K).

What is the maximum limit of array size in C programming?

7 Answers. Save this answer. Show activity on this post. There is no fixed limit to the size of an array in C.

What is the maximum size of a global array?

array size 10^7 to 10^8 declared globally(i.e. on heap) is possible…if u declare nething in the main or in ne fxn…it goes into the stack which has a smaller size hence ur 10^7 array did not work out…

Is array size static?

Static arrays have their size or length determined when the array is created and/or allocated. For this reason, they may also be referred to as fixed-length arrays or fixed arrays. Array values may be specified when the array is defined, or the array size may be defined without specifying array contents.


1 Answers

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.
like image 104
Siddhartha Ghosh Avatar answered Sep 20 '22 21:09

Siddhartha Ghosh