Jump to content

Talk:Variable-length array

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Loadmaster (talk | contribs) at 16:30, 14 October 2009 (Only automatic?: other languages mentioned). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

stored where?

i think it is only on stack. but there might be cases where it is on heap due to size or just language way of dealing with ADT's. i ask for i added that it is typycally on stack onto main page. 84.16.123.194 (talk) 20:01, 23 October 2008 (UTC)[reply]

Depends on the language and implementation. In C (C99), it's on the stack, i.e., VLAs can only have auto storage class. In COBOL, it's either the WORKING-STORAGE or FILE SECTIONs, which are static data areas, or in the LINKAGE SECTION, which may be static to another program module or allocated on the heap (e.g., using EXEC CICS GETMAIN). — Loadmaster (talk) 20:19, 23 October 2008 (UTC)[reply]
thanks. should it be mentioned here? 84.16.123.194 (talk) 21:33, 23 October 2008 (UTC)[reply]

Only automatic?

I wouldn't say that the term "variable length array" is limited to any one storage duration. I would consider the term entirely appropriate for any array of non-fixed size, including arrays allocated out of a heap or arrays (as in awk and Perl) with no fixed size. (In fact, I would consider the awk/Perl to be *true* variable-length arrays, whereas C99 has fixed-length arrays with the length determined at execution time.) Jordan Brown (talk) 21:03, 23 April 2009 (UTC)[reply]

Of course, the length of dynamically allocated arrays (including resizable/dynamic arrays) doesn't have to be known at compile time, and you could trivially consider them to have a "variable length". But they are not what the term "Variable-length array" refers to, at least in the context of the C language. -- memset (talk) 12:21, 24 April 2009 (UTC)[reply]
But the article mentions lanugages other than C, too. What to do? We don't want to duplicate the Dynamic memory allocation article. — Loadmaster (talk) 16:30, 14 October 2009 (UTC)[reply]