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 11:51:16 -0700 Organization: None to speak of Lines: 69 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> <157e3a8c-edb9-403d-8f50-765b8407a0a4@googlegroups.com> <3OSpC.3$rz2.0@fx19.am4> <99f65454-96b9-4a22-8f2b-6a49ec7b3790@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="a9638e2b58572a27edc6516887e5eee0"; logging-data="12090"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19HtpY/ov/xw2TtCKQoEHjp" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:48mSJA8u5X7jLcysw4MpG0gII5w= sha1:o6SNoBmbnRUzwAbXmn8/IYLa78w= Xref: csiph.com comp.lang.c:127763 jameskuyper@verizon.net writes: > On Tuesday, March 13, 2018 at 12:15:04 PM UTC-4, Bart wrote: >> On 13/03/2018 14:45, jameskuyper@verizon.net wrote: >> > What the standard says about variable length arrays is slightly >> > different: "For such an object that does have a variable length array >> > type, its lifetime extends from the declaration of the object until >> > execution of the program leaves the scope of the declaration. ..." >> > (6.2.4p7). >> >> > int main(int argc, char *argv[]) >> > { >> > #ifdef DEFINED_BEHAVIOR >> > #define N 5 >> > #else >> > const int N = argc; >> > #endif >> > >> > int *pi = 0; >> > label: >> > if( p ) >> > return *pi; >> > int array[N] = {0}; >> > pi = array; >> > goto label; >> > } >> > >> >> >> What about the example below? It loops via goto (so no blocks to exit or >> reenter, and each time it generates a new size for array B. >> >> So, does it recover the stack space from the old allocation, or does it >> just forget about it and allocate a new array? > > Footnote 35 points out that "Leaving the innermost block containing the > declaration, or jumping to a point in that block or an embedded block > prior to the declaration, leaves the scope of the declaration.", > something you should have been able to figure out from the normative > text. Therefore, the lifetime of B ends each time that the goto is > executed. the next time the declaration of B is encountered, it creates > a new object. I was about to say that you're confusing scope and lifetime, but that sentence has to be read in combination with 6.2.4p7: For such an object that does have a variable length array type, its lifetime extends from the declaration of the object until execution of the program leaves the scope of the declaration. It's slightly odd to say that execution of the program (a run-time concept) is inside or outside a particular scope (a region of program text), but it does work. [...] > C90 deals with the issue you raise by saying to following about > sizeof(expression): "If the type of the operand is a variable length > array type, the operand is evaluated; otherwise, the operand is not > evaluated and the result is an integer constant." (6.5.3.4p2). You mean C99 or C11. [...] -- 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"