Date: Thu, 12 Feb 1998 13:48:33 +0200 (IST) From: Eli Zaretskii To: Noam Rotem cc: zager AT post DOT comstar DOT ru, djgpp AT delorie DOT com Subject: Re: Dynamically declaring 2-d arrays In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Wed, 11 Feb 1998, Noam Rotem wrote: > >{ int arr[x][y]; > > This sounds very odd... Can I then return arr and use it as every other > dynamic allocation? No, this array is allocated from the stack, not from the heap (where `malloc' gets its memory). What GCC does is to call `alloca' function after the array dimensions are computed at run time. > What's the type of arr in this case? Exactly as if you were to declare it at compile time: the type is arr[x][]. > Can you explain how it is implemented by GCC? See above: it's just a call to `alloca'. You can do it yourself as well: { size_t a = strlen(foo) + 1; char *arr = alloca (a); .... arr[i] = 'x'; } For more details, type "info gcc 'C Extensions' 'Variable Length'" from the DOS prompt.