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: Thu, 15 Mar 2018 10:45:43 -0700 Organization: None to speak of Lines: 33 Message-ID: References: <0231327b-9e28-46e4-9178-46c881a8dd91@googlegroups.com> <5e80c990-fe53-4d7e-8a81-bc411cc21d76@googlegroups.com> <2ac9ccf7-5b25-4822-8dbd-5b749bed2c07@googlegroups.com> <1m0qne-g741.ln1@wilbur.25thandClement.com> <5c7ff91c-df09-4b26-af04-415217aef572@googlegroups.com> <2_wqC.6105$mD2.1220@fx33.iad> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="4062d3804107f3b0a8439aa53526a52c"; logging-data="4354"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18OLUqzSb0wN/HmLCVWSm04" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:NMCJDL+8Q1OzBU90Flh3WXF97sU= sha1:OsJ74iGXnGQDvtH1F0kK8aaLk7k= Xref: csiph.com comp.lang.c:127881 scott@slp53.sl.home (Scott Lurndal) writes: > supercat@casperkitty.com writes: >>On Thursday, March 15, 2018 at 7:35:24 AM UTC-5, David Brown wrote: >>> Secondly, it's okay if the VLA allocated space has longer lifetime than >>> its block - it's only a problem if the lifetime is too short! You might >>> have less efficient code if the allocation remains for longer than >>> necessary, but that is of secondary importance. >> >>Nothing on a stack can have a longer lifetime than anything that was >>allocated previously. A data structure where later-created objects >>can have a longer lifetime is not a stack. > > A function is perfectly free to allocate more stack as it runs. It > doesn't need to deallocate any of it until it returns to the caller. > So, a VLA allocated in a block within the function can safely remain > extant until the function itself exits - it's scope lifetime has > ended, but the storage for it remains until the function exits. The same argument could imply that it's perfecly valid for local storage for a function call not to be deallocated even when the function returns. Just allocate each "stack frame" on the heap, and don't bother calling free(). If I were implementing VLAs in a compiler, I might consider an initial proof-of-concept implementation that doesn't deallocate until the function returns, but I'd argue against sending that implementation out the door. -- 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"