Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: local arrays and stack Date: Tue, 24 Mar 2015 13:42:43 -0700 Organization: None to speak of Lines: 42 Message-ID: <87384urut8.fsf@kst-u.example.com> References: <87k2y7u48c.fsf@kst-u.example.com> <705a5674-dbc9-460a-a72c-50bf1946be01@googlegroups.com> <87fv8vu1sx.fsf@kst-u.example.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="c77ff4d35e33d1c939d3461ebde8dd0d"; logging-data="24266"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Iyy3wY9wQwf5EAAZAMfuU" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:wLaPoqb4KOIlK01NOJV+14ZsuAg= sha1:SEdageJOjTyt+dt766W47ewfOHw= Xref: csiph.com comp.lang.c:58877 Tim Rentsch writes: > Keith Thompson writes: >> Bartc writes: >>> [snip] >> >> Does gcc *ever* (generate code to) allocate local non-static >> arrays on the heap or in static memory? It would have to generate >> code to explicitly deallocate the array, even in the presence of a >> goto or longjmp() out of the scope. [snip] > > Certainly it would be nice if a compiler did manage to deallocate > such arrays even in the presence of longjmp(), but strictly > speaking I'm not sure there is a requirement to do so. So I > think that's a QoI issue, not a conformance problem. Note that > for VLA's there is an (informative) explicit remark in the > Standard about this, in 7.13.2.1 p5. I don't see any text in the > Standard that makes arrays that are not VLA's different in this > regard (or for that matter, non-arrays either - if we had a big > struct we might very well want to allocate it using non-stack > memory). The cited remark is: EXAMPLE The longjmp function that returns control back to the point of the setjmp invocation might cause memory associated with a variable length array object to be squandered. But paragraph 2 specifically addresses VLAs: ... or if the invocation of the setjmp macro was within the scope of an identifier with variably modified type and execution has left that scope in the interim, the behavior is undefined. (If you're going to cite the standard, it would be useful to copy-and-paste the actual text, or at least summarize it, for those who don't have a copy handy.) -- 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"