maximum number of dimensions in C/C++ array

andre maute andre.maute@gmx.de
Sun May 14 21:39:00 GMT 2006


On Sunday 14 May 2006 23:27, Brian Dessent wrote:
> 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.

What i really want to do, is to generate header files with const array's,
with at least 8 dimensions. This happens within my numerical integration code.

So there should be no problem with the stack.

I.e. i want to know how many dimensions the compiler is supposed to cope with, 
when parsing the const array.

Andre



More information about the Gcc-help mailing list