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: Tue, 13 Mar 2018 09:38:05 -0700 Organization: None to speak of Lines: 35 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="6964"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/YrAopIWTotfV8tIaFu9p5" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:oJyPTzEYHEvaryD5jD44Iv90jcw= sha1:HiY76wqq3xOpuIEbeT4XOrClKNY= Xref: csiph.com comp.lang.c:127756 David Brown writes: > On 13/03/18 02:24, Keith Thompson wrote: [...] >>> On 12/03/2018 23:24, Keith Thompson wrote: [...] >>>> #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]; >>>> } [...] >> Sure, I'd expect some fairly small fixed overhead for a VLA compared to >> a fixed array of the same length. > > When the size is known at compile time, I would not expect any overhead > of a VLA compared to a fixed size array (such as in your examples here). A compiler could determine the value of var, but that wasn't my intent. (Note that there's no "const".) Consider the initialization of var to be replaced by something that can't reasonably be determined at compile time. Some VLAs can be optimized to be equivalent to fixed-length arrays, but that's not what I was talking about. -- 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"