🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #1305

Re: C: a question about scope automatics in C

#1305
From: Ross Finlayson
Date: Tue, 03 Nov 2026 16:16
121 lines
6963 bytes
On 11/03/2026 08:08 AM, David Brown wrote:
> On 03/11/2026 16:14, Ross Finlayson wrote:
>> On 11/03/2026 02:47 AM, David Brown wrote:
>>> On 02/11/2026 19:38, Ross Finlayson wrote:
>>>>
>>>> C: a question about scope automatics in C
>>>>
>>>> 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. C++ of course has that's the usual way of
>>>> things with stack-allocation and block-scope for automatics,
>>>> I'm wondering if there's any way C makes it so (I think not,
>>>> yet would be glad to know so).
>>>>
>>>>
>>>> If not, are there common compiler extensions to so indicate
>>>> when a variable goes out of scope and make effects on it?
>>>>
>>>> Thanks for reading, also I'd be interested your opinion.
>>>>
>>>
>>> As has been pointed out by several people, if you want helpful answers,
>>> you will have to make a lot more effort to write clear, grammatical
>>> English.  Most of what you write is barely comprehensible.  Try thinking
>>> before you write, split text into sentences and paragraphs, and then
>>> re-read what you have written.  Maybe it would help if you give some
>>> examples in C.
>>>
>>> It would also be useful if you tried to stay up to date with modern C
>>> standards, but of course it is fine to ask about the details.  Most C
>>> programmers don't read the standards or proposals, but there is no point
>>> in trying to invent "new" features if they are already in the language,
>>> or likely to come in the near future.
>>>
>>> And please do not post extracts from some AI chatbot.  If you want to
>>> use these tools as a source of information, that's up to you - they can
>>> be useful research assistants, but are often inaccurate.  (I only read a
>>> little of your "GG" post, and there was a lot wrong in it.)  People in a
>>> group like comp.lang.c are here to talk with, listen to, learn from and
>>> help other people.  If we want AI slop, we know where to find it
>>> ourselves.
>>>
>>>
>>> As to the particular matter in hand - running some sort of clean-up code
>>> when a local variable's lifetime ends - you should first understand that
>>> it is the variable's /lifetime/ that is important, not its scope.  For
>>> local variables that are not declared "static", these are closely
>>> related.  But "scope" is about when the identifier's name can be used,
>>> "lifetime" is when the object itself exists.
>>>
>>> For gcc (and clang, and perhaps other compilers), you can use the
>>> "cleanup" attribute to run code at the end of the lifetime of an
>>> automatic storage duration variable.  (The gcc documentation incorrectly
>>> says "scope", and gives no information about complicated situations such
>>> as using "goto" or "longjmp".)
>>>
>>> <https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#index-cleanup>
>>>
>>>
>>>
>>> For the future, it is likely that C will gain a "defer" feature in the
>>> next C standard (currently known as C2y).  Macros to get an approximate
>>> version of this are available, using gcc extensions.  Here is a simple
>>> one :
>>>
>>> <https://antonz.org/defer-in-c/>
>>>
>>> More advanced versions can be found on Jens Gustedt's blog :
>>>
>>> <https://gustedt.wordpress.com/2025/01/06/simple-defer-ready-to-use/>
>>> <https://gustedt.wordpress.com/2026/02/15/defer-available-in-gcc-and-
>>> clang/>
>>>
>>>
>>>
>>
>>
>> It's appreciated about "cleanup" and "defer" as
>> with regards to instrumenting code at entry and exit,
>> of function-scope and block-scope.
>>
>> Hm. Maybe a story will help. (Maybe it won't.)
>>
> It didn't help.  Your writing is absolute tripe.  I have no idea what
> you are trying to say, or what you are trying to ask - I can't even tell
> if you are actually asking anything.
>
> If the information about gcc's "cleanup" attribute and the macros and
> C2y "defer" proposal helps you, that's great.
>
> But if you can't write understandable text, there is no point in
> discussing further.
>
> Writing sixty words per minute is useless when the words don't convey
> information.  Reading "a million miles per hour" is useless when you do
> not take in the content of what you are reading.
>


Hm. "Computronomat: natural language understanding, computational
linguistic comprehension", is a video essay or lecture recorded the
other day, I suppose that sounds like non-sense, also.


I'm not trying to cause trouble - just pointing out an opportunity
to make for a convention (code-convention and calling-convention and
compiler-convention and idiom and thei discipline), so that these
sorts "automatic temporary arrays", when they fit, can be accessed
as restrict'ed pointers allocated (according to the implementation,
according to the specification, so pretty much according to alloca()
on the implementation, standard language specification guardians),
a "perceived requirement" as with regards to "perceived deficiencies",
about high-performance high-reliability systems code.

Does that make sense so far, yet?

Technical Details
Message-ID: <mdicnZHlMZlPlXf3nZ2dnZfqnPednZ2d@giganews.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.nrbbs.org!border-3.nntp.ord.giganews.com!nntp.giganews.com!local-2.nntp.ord.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
References: <oOScndMmgZhYRXX3nZ2dnZfqnPGdnZ2d@giganews.com> <11cce4h$3m11i$1@dont-email.me> <8V2dnW6M3YIeZ3T3nZ2dnZfqn_SdnZ2d@giganews.com> <11cd0tn$3tbkg$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.nrbbs.org!border-3.nntp.ord.giganews.com!nntp.giganews.com!local-2.nntp.ord.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 16:16:18 +0000
Subject: Re: C: a question about scope automatics in C
Newsgroups: comp.lang.c
References: <oOScndMmgZhYRXX3nZ2dnZfqnPGdnZ2d@giganews.com>
 <11cce4h$3m11i$1@dont-email.me>
 <8V2dnW6M3YIeZ3T3nZ2dnZfqn_SdnZ2d@giganews.com>
 <11cd0tn$3tbkg$1@dont-email.me>
From: Ross Finlayson <ross.a.finlayson@gmail.com>
Date: Tue, 3 Nov 2026 08:16:16 -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: <11cd0tn$3tbkg$1@dont-email.me>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <mdicnZHlMZlPlXf3nZ2dnZfqnPednZ2d@giganews.com>
Lines: 121
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-BH4PS6/oYhzxaQOXfYMvg9wE4bisgBwWKOTWEntOrQY9kdQNw3jMf9SiZu89l8XNxSJlDeOMGKGgwFl!0kl7tBUs1Sny7UGTqnROyFuMNzJvkFmmnCCplOWp0QA6JOtgN/46AEBxzHmlCBpfdRyZK3uSCO4=
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