Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Future of C Date: Mon, 12 Mar 2018 18:24:16 -0700 Organization: None to speak of Lines: 49 Message-ID: References: <0231327b-9e28-46e4-9178-46c881a8dd91@googlegroups.com> <20180310180016.eda9bc36e1a3b182bc2563a8@gmail.com> <20180311000302.8e7cd15242a818ab75eb2e98@gmail.com> <83527acf-abed-4f8f-878c-7d4db9cd5ac1@googlegroups.com> <20180311161525.ac591de531b83d6b14b2cd43@gmail.com> <90236828-48d7-4ee5-9b86-4cedd0e29b5f@googlegroups.com> <3r7jne-t3h.ln1@gangtai.grep.be> <8e201938-ada4-42d9-8ae6-13b1047306e2@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="a9638e2b58572a27edc6516887e5eee0"; logging-data="22898"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9hy8vvYP5fqeA4UX8+wdg" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:MzgBYDGB1/TEgCfyWiE6bUo+AIk= sha1:JaCVVxIENvYPvRTvveSM7Bcq9bs= Xref: csiph.com comp.lang.c:127728 bartc writes: > On 12/03/2018 23:24, Keith Thompson wrote: >> supercat@casperkitty.com writes: [...] >>> How are programmers supposed to judge whether a >>> VLA declaration of a given size would be reasonable? >> >> Take the above paragraph and replace each occurrence of VLA by >> constant-length array. >> >> #define SOME_BIG_NUMBER /*...*/ >> >> void func1(void) { >> int fixed_array[SOME_BIG_NUMBER]; >> } >> >> void func2(void) { >> size_t var = SOME_BIG_NUMBER; >> int vla[var]; >> } > > Nevertheless it is useful for both compiler and programmer when an array > size is known at compile-time. Nevertheless, it can be useful to be able to define array objects whose length is not a compile-time constant. Feel free not to use the feature if you don't like it. > Your second example is unrealistic, and probably only happens when > someone thinks that a const int variable can be used as an array length; > it can, but only by creating a VLA which might have been unintended. The second example was not intended to be realistic. It was meant to parallel the first example as closely as possible, to demonstrate that VLAs don't introduce any fundamental new problems that don't already exist for fixed arrays. > (On Windows, a large fixed array requires special stack allocation code. > With a VLA, it doesn't know what size it is so needs to use the special > code even if the size turns out to be small.) Sure, I'd expect some fairly small fixed overhead for a VLA compared to a fixed array of the same length. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"