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/>
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.)
On 03/11/2026 16:14, Ross Finlayson wrote:
On 11/03/2026 02:47 AM, David Brown wrote:It didn't help. Your writing is absolute tripe. I have no idea what
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.)
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?
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:It didn't help.ÿ Your writing is absolute tripe.ÿ I have no idea what
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.)
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?
On 03/11/2026 16:16, Ross Finlayson wrote:
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?
No. You sound just like a badly programmed bot.
If not, are there common compiler extensions to so indicate
when a variable goes out of scope and make effects on it?
Then, if one of these records has some dozens, scores, or hundreds
of fields, among textual, numeric, and calendric built-in and
user-defined types, then each one of these might need a buffer or
buffers the scratch-pad or working-memory, as the working-memory of
the conversion & formatting routines, since for example strtok and
strtok_r and other accounts of the conversion & formatting after the accessor/mutator routines of the records their fields in accounts of structured programming: are always using temporaries, here
"automatic temporary arrays", their buffers.
On Tue, 3 Nov 2026 09:02:32 -0800, Ross Finlayson wrote:
Then, if one of these records has some dozens, scores, or hundreds
of fields, among textual, numeric, and calendric built-in and
user-defined types, then each one of these might need a buffer or
buffers the scratch-pad or working-memory, as the working-memory of
the conversion & formatting routines, since for example strtok and
strtok_r and other accounts of the conversion & formatting after the
accessor/mutator routines of the records their fields in accounts of
structured programming: are always using temporaries, here
"automatic temporary arrays", their buffers.
Basically, a complex, dynamically-allocated data structure with an
intricate collection of components which themselves need dynamic
allocation? Need to deal with errors that might occur during the setup
and usage of such a structure, to ensure that all memory allocated is properly freed, without the chance of double-frees or memory leaks?
Been there, done that. I use a technique called ?structured
programming? to deal with the whole issue.
Have a look at this project: <https://gitlab.com/ldo/a_structured_discipline_of_programming>. The
README gives an introduction to the concept, and the sample code
illustrates it in (I hope) exhaustive detail.
On Tue, 3 Nov 2026 09:02:32 -0800, Ross Finlayson wrote:
Then, if one of these records has some dozens, scores, or hundreds
of fields, among textual, numeric, and calendric built-in and
user-defined types, then each one of these might need a buffer or
buffers the scratch-pad or working-memory, as the working-memory of
the conversion & formatting routines, since for example strtok and
strtok_r and other accounts of the conversion & formatting after the
accessor/mutator routines of the records their fields in accounts of
structured programming: are always using temporaries, here
"automatic temporary arrays", their buffers.
Basically, a complex, dynamically-allocated data structure with an
intricate collection of components which themselves need dynamic
allocation? Need to deal with errors that might occur during the setup
and usage of such a structure, to ensure that all memory allocated is properly freed, without the chance of double-frees or memory leaks?
Been there, done that. I use a technique called ?structured
programming? to deal with the whole issue.
Have a look at this project: <https://gitlab.com/ldo/a_structured_discipline_of_programming>. The
README gives an introduction to the concept, and the sample code
illustrates it in (I hope) exhaustive detail.
So, malloc and free are system-calls, in the implementation
or the runtime or the O.S., and so when the structure is
already in the code or data-segment, and needn't be
re-entrant, then these system-calls can be reduced.
Well, thanks all, looking directly at variable-length-arrays,
it seems that variable-length-arrays solve my riddle with
making "automatic temporary arrays" as reside in the stack-segment
and are block-scoped and while perhaps to be touched before access
to avoid page-faults, are just the thing.
Thanks, I think I solved my problem by "not re-inventing the wheel".
Well, thanks all, looking directly at variable-length-arrays,
it seems that variable-length-arrays solve my riddle with
making "automatic temporary arrays" as reside in the stack-segment
and are block-scoped and while perhaps to be touched before access
to avoid page-faults, are just the thing.
[ ... ]
Thanks, I think I solved my problem by "not re-inventing the wheel".
Then, it's figured there's a standard C way to make "automatic temporary arrays". Then there's alloca() when that's not available, else there isn't.
So, then the next sort of perceived requirement here is about buffers
and ownership of buffers and transfer, exchange, or passing of buffers
in the ownership (and responsibility), when, for example, a buffer is partially filled in one thread-of-control, and passed to an I/O
sub-system that correspondingly is under another thread-of-control,
variously in user-space or kernel-space, which is undefined by C yet
common in all commodity operating systems (with regards to executives
and schedulers, those being simpler accounts of operating systems).
Then, there's an idea, about how to handle thread-death, and basically
about a two-state approach to free-lists, or freeable and freed,
usually enough "acquire" and "release", when the relevant sub-system
of I/O, might or might not have any way to indicate to free (or delete,
to de-allocate, to release, to make discardable and discarded) the buffers.
Then, there's considered a sort of belt-and-suspenders approach,
to that a process allocates memory to build a free-list with a system
call, about the various contexts of "heap memory" and also the section "direct memory" when that's separate about DMA and its usual role
in I/O subsystems, then that only malloc (calloc, realloc) and free
have semantics to the O.S. otherwise that the process must die for
all what's malloc'ed to be free'd, when there are cases of thread-death
or errors & exceptions, that a belt-and-suspenders approach involves interacting efforts to manage the resources, or redundancy.
So, a usual allocation might figure to allocate a fixed amount of
resources, then to use the sort of automatic throttling that in
a web server or Internet server that it auto-throttles that when
there are no available buffers that reads stop and the O.S. and NIC
make TCP/IP advertise the window closing so TCP/IP makes back-pressure,
that though the memory is all allocated up-front so that it's figured
the run-time never grows in memory so that usual sorts of infrastructure deployments the nodes the runtimes the virtualized/chrooted account of multi-tenancy in server clusters and server processes and process-groups
with cgroups after ulimit and the like and "Out-of-Memory Killer" and so
on, make for usual expectations of long-lived processes and availability
and uptime.
Then, whether a linked-list or an array, of buffers, the free-list or free-array, makes for that I/O buffers come and go and not necessarily in-order, not necessarily that they're out-of-order, yet that they're formally un-ordered, as to why a free-list is usually the idea since
that insertions and removals are O(1), yet that a free-array is usually
the idea since that random-access is O(1), then about the constant fragmentation and de-fragmentation, usually that a list involves a lot
of points, that for example when it's a fixed-size list, those can be an array the pointers, and they're followed by pointer increment and
pointer addition, the pointers of the linked-list.
So, besides the datum of the item in the list, then makes for probably
a time-out or LRU eviction/reclamation policy, which though depends
on the entire framework the longest-lived valid ownership, to be under
that.
So, since the usual consideration brings definition of POSIX after C
brings definition, what that means is signals or out-of-band events that basically destroy the expectations of the behavior of the runtime, about
that also the signal-handlers must be completely brief and non-blocking,
else that the kernel may carp or choke, about "installing items from the free-list that were reserved yet not passed to another
thread-of-control's responsibility to the signal-handler", that the signal-handler can release those, along with for example marking that it stomped or killed the thread that received it, as for the process as the process-of-control and the thread which is the thread-of-control.
So, here then there's an idea about the thread-of-control, there's
basically for that I'm not too familiar the semantics of basically
"POSIX, or, Windows", of what signals make for semantics, or in the
world of structured-exception-handling or SEH in Windows, say, of thread-death or thread-join or cascading signals, what would define then whether post-signal, the thread, could detect, courtesy a thread-local-variable, for example, whether, and how, it should cleanup itself, since it was interrupted by a signal. Then, whether that's recoverable or irrecoverable, fatal, after accounts of the PCB process-control-block and the TCB thread-control-block, those being
common concepts among operating systems their schedulers, if not saying
much about "fibers" or similar sorts accounts of "not-quite-threads, not-quite-processes", about how to make it so that usual server
processes are long-lived and to handle both the burst-y and the idle,
without tipping over.
So, now my question is how to approach the usual sort of commodity
operating system its runtime, for example POSIX and C, to be a good
actor in the resource management, in a setting that's mostly organized
about co-operative asynchrony for concurrency.
| Sysop: | Jacob Catayoc |
|---|---|
| Location: | Pasay City, Metro Manila, Philippines |
| Users: | 5 |
| Nodes: | 4 (0 / 4) |
| Uptime: | 498678:37:05 |
| Calls: | 212 |
| Calls today: | 3 |
| Files: | 912 |
| D/L today: |
31 files (22,593K bytes) |
| Messages: | 69,880 |