🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #1310

Re: C: a question about scope automatics in C

#1310
From: David Brown
Date: Tue, 03 Nov 2026 16:47
142 lines
7514 bytes
On 03/11/2026 17:16, Ross Finlayson wrote:
> 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?
> 
Sorry, no.

I realise you are not trying to "cause trouble", just as I am not trying 
to be rude.  Again, I would urge you to write short, clear C code to 
express what you are trying to say.  Hopefully that will work better 
than when you try to write prose.

If all you wanted to ask about has already been answered with "cleanup" 
and "defer", then we should leave it at that.


Technical Details
Message-ID: <11cd36u$3v696$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <oOScndMmgZhYRXX3nZ2dnZfqnPGdnZ2d@giganews.com> <11cce4h$3m11i$1@dont-email.me> <8V2dnW6M3YIeZ3T3nZ2dnZfqn_SdnZ2d@giganews.com> <11cd0tn$3tbkg$1@dont-email.me> <mdicnZHlMZlPlXf3nZ2dnZfqnPednZ2d@giganews.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c
Subject: Re: C: a question about scope automatics in C
Date: Tue, 3 Nov 2026 17:47:26 +0100
Organization: A noiseless patient Spider
Lines: 142
Message-ID: <11cd36u$3v696$1@dont-email.me>
References: <oOScndMmgZhYRXX3nZ2dnZfqnPGdnZ2d@giganews.com>
 <11cce4h$3m11i$1@dont-email.me>
 <8V2dnW6M3YIeZ3T3nZ2dnZfqn_SdnZ2d@giganews.com>
 <11cd0tn$3tbkg$1@dont-email.me>
 <mdicnZHlMZlPlXf3nZ2dnZfqnPednZ2d@giganews.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 03 Nov 2026 16:47:27 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="4167974"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/i1NtGiMs67Gm9F24nCEc043002uJjNX4="; posting-host="f06b12b7403cf57442a23e3e44a23173"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:c/WT7/cwmW1z0pRmrtzH8mwiSa8= sha256:2ta2SjrFa//d4VeLWxxb/FQYCZiO/o+fkB2TF+MSfow=
	sha1:0UEtaexjD5boRe73NkcwWXrFtok= sha256:o1a4EqBMXgyjqDy6H2kE1NSW8sIRlSlGIACwhgkyts4=
In-Reply-To: <mdicnZHlMZlPlXf3nZ2dnZfqnPednZ2d@giganews.com>
Content-Language: en-GB, nb-NO