This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: maximum number of dimensions in C/C++ array


andre maute wrote:

> Has somebody an idea where to find the maximum number
> of dimensions for declaring an array?
> How many are supported within GCC and how many are
> mandated by the standards?
> 
> e.g.
> 
> double v[n1][n2][n3];
> declares obviously a  3-dimensional array of doubles.

The problem is that declaring an array that way causes it to be
allocated on the stack, and the stack is not a good place to allocate
large amounts of memory.  You will almost certainly overflow the stack
trying to do this.  If instead you use malloc() and pointers, you can
allocate arrays to any arbitrary depth, bounded only by total available
memory.

Brian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]