Mail Archives: djgpp/1998/02/12/06:48:55
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.
- Raw text -