Article View: comp.lang.c
Article #1282Re: C: a question about scope automatics in C
From: Ross Finlayson
Date: Tue, 03 Nov 2026 01:19
Date: Tue, 03 Nov 2026 01:19
114 lines
5991 bytes
5991 bytes
On 11/02/2026 03:09 PM, Keith Thompson wrote: > Ross Finlayson <ross.a.finlayson@gmail.com> writes: >> C: a question about scope automatics in C > > No need to mention C in the subject (twice). We know what newsgroup > we're in. > >> Hello, I hope someone can tell me whether C may make >> for scope automatics any account of attaching side-effects >> to block-declared variables about scope-exit of automatics >> making for any way in C to attach behavior to scope-exit, >> or any way to make for when a variable goes out of scope >> (block-scope, or, function-scope) to make any account of >> cleanup of it. > > FWIW, you could have probably said that more clearly with about a > third as many words. > > You mentioned alloca() in a followup. Memory allocated by alloca() is > deallocated on exit from the function, not on leaving a smaller scope. > And of course alloca() is non-standard (not even specified by POSIX). > > There's a proposal for C2y, adding a new _Defer keyword. > > https://www.open-std.org/jtc1/sc22/wg14/www/docs/n4001.pdf > Thanks. I figure that "storage-class" is thoroughly defined in C, then with regards to stack-segment and data-segment, that being more-than-less common. Looking at something like "WG14/N1256 Committee Draft — Septermber 7, 2007 ISO/IEC 9899:TC3", I'm not sure what "Septermber" is, yet generously read it's a month of the year, Annex C is for "Sequence points", that 7.20.3 has "Memory management functions" that I can see there, about 6.2.2 "Linkages of identifiers", 6.2.4 "Storage durations of objects", from 6.2.4 "An object whose identifier is declared with no linkage and without the storage-class specifier static has automatic storage duration." "For such an object that does not have a variable length array type, its lifetime extends from entry into the block with which it is associated until execution of that block ends in any way." "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." Then, variable-length arrays must probably already live in the stack-segment somewhere, yet the idea here is how to maintain the storage duration, with regards to systems like POSIX with threads, if C doesn't much say. Then, it seems I'm mostly caring what GCC does, while to keep behavior un-surprising, mostly about in-memory text in the stack-segment, that only uses as many buffers as are in effect in use in the function and block scopes, then separately the buffers from a free-list for asynchronous I/O, so memory-management is approached by not allocating or de-allocating anything, yet that the data-segment isn't re-entrant and thread-stack-segment is quite a blob, that this idea of making the type and call-graph inference about the intent and use of these buffers, automatic temporary arrays, has them simple. "An array type describes a contiguously allocated nonempty set of objects with a particular member object type, called the element type. 36) Array types are characterized by their element type and by the number of elements in the array. An array type is said to be derived from its element type, and if its element type is T , the array type is sometimes called ‘‘array of T ’’. The construction of an array type from an element type is called ‘‘array type derivation’’." (6.2.5.20 item the first) So, the lifecycle of duration appears to be "blocks" or block-scope, vis-a-vis functions or function-scope and that just being a block, then about "storage-class", here as alike "auto", then as with regards to being arrays, that they're addressable and pointer arithmetic works on them, and not involving "trap representations", then: that it's on the host (the C host) as to how that's implemented. 5.1.2.3: "The semantic descriptions in this International Standard describe the behavior of an abstract machine in which issues of optimization are irrelevant." "The least requirements on a conforming implementation are: — At sequence points, volatile objects are stable in the sense that previous accesses are complete and subsequent accesses have not yet occurred. [...]" 5.2.4.1 "Translation limits", 6.10.6 "Pragma directive" 6.10.9 "Pragma operator" So, it's a number of questions about "implementation-defined behavior in C".
Technical Details
Message-ID:
<MVCdnSzYwpQKq3T3nZ2dnZfqn_udnZ2d@giganews.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!weretis.net!feeder9.news.weretis.net!border-3.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mailReferences:
<oOScndMmgZhYRXX3nZ2dnZfqnPGdnZ2d@giganews.com> <11cb56q$39nj8$2@kst.eternal-september.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!weretis.net!feeder9.news.weretis.net!border-3.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 03 Nov 2026 01:19:19 +0000 Subject: Re: C: a question about scope automatics in C Newsgroups: comp.lang.c References: <oOScndMmgZhYRXX3nZ2dnZfqnPGdnZ2d@giganews.com> <11cb56q$39nj8$2@kst.eternal-september.org> From: Ross Finlayson <ross.a.finlayson@gmail.com> Date: Mon, 2 Nov 2026 17:19:05 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <11cb56q$39nj8$2@kst.eternal-september.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Message-ID: <MVCdnSzYwpQKq3T3nZ2dnZfqn_udnZ2d@giganews.com> Lines: 114 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-wSpxzowBbb57aQs/6If3+m4Z6tQHb5n89eAfqcLuw0WBwYZZEAiPcOVmcMRtQJTEMBk6yqJnY9nclF1!BSHi8ba5yJhJyWwdREn+pmXY+CeU+GelR4ZPTd5Dklz0cGVsfZknc12I44DPw7nfp+vRO8JgYhQ= X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40