Article View: comp.lang.c
Article #1317Re: C: a question about scope automatics in C
From: Ross Finlayson
Date: Wed, 04 Nov 2026 00:17
Date: Wed, 04 Nov 2026 00:17
97 lines
5518 bytes
5518 bytes
On 11/03/2026 03:12 PM, Lawrence D’Oliveiro wrote:
> 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.
>
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.
So, elsewhere:
__attribute__((noinline))
size_t pg_sz() {
return 2 * PAGE_SIZE - 1;
}
ptr_t pg_algn(ptr_t stack_offset) {
return stack_offset + PAGE_SIZE - 1 - (stack_offset & (PAGE_SIZE - 1));
}
#define PG_BUF ({ size_t _pg_sz = pg_sz(); char
_unaligned_stack[_pg_sz]; (char*) pg_algn((ptr_t) _unaligned_stack); })
Then, chatting with the bot tells me that "variable-length-array
declaration" has some specific syntax involved, as if array declarations
the initialization weren't already quite various though nice once
figured, and it tells me that the "macro" to result this
PAGE_SIZE buffer resident in the stack-segment has that ANSI C
would have to have passed the name and then string-token-concatenate
it "##", that though "GCC/Clang" "statement expressions" make for this
sort of macro.
Then, somewhere:
char* __restrict__ buf = PG_BUF;
Why I'm looking for this "automatic temporary arrays", is that I've
tapping away at some low-level code for text, i.e. Unicode text,
called "Viswath & Charmaigne", as I tapped up over at comp.theory,
then with that being a bunch of assembler macros, about an
algorithm/procedure/routine/function setup, then I started looking
at ye olde "string atomization" or as with regards to handles or
internment of strings, "Atomenom", for this sort of "mechanical
sympathy", about cache-line-size, which is sort of 64B everywhere
and mostly in pairs of those, page-size, which is mostly 4KiB everywhere
yet according to PAGE_SIZE, then as with regards to small/medium/large
pages, and about general-purpose processor
widths as 64-bit or "Gompath" I'm calling it, then about the
vector-register widths as 128-bit then in tandem units for what can make
shift & rotate, the "Viswath" bit, then as getting into what would
be free-lists of PAGE_SIZE to be passed around, first wanted to get
figured out "automatic temporaries" of PAGE_SIZE to not be passed around.
Thanks, I think I solved my problem by "not re-inventing the wheel".
Technical Details
Message-ID:
<JWmdncGFCcoC5Hf3nZ2dnZfqnPGdnZ2d@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-3.nntp.ord.giganews.com!Xl.tags.giganews.com!local-4.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mailReferences:
<oOScndMmgZhYRXX3nZ2dnZfqnPGdnZ2d@giganews.com> <11cce4h$3m11i$1@dont-email.me> <8V2dnW6M3YIeZ3T3nZ2dnZfqn_SdnZ2d@giganews.com> <11cd0tn$3tbkg$1@dont-email.me> <mdicnZHlMZlPlXf3nZ2dnZfqnPednZ2d@giganews.com> <11cd22m$3tpfp$2@dont-email.me> <x8adnYBW_KQgjnf3nZ2dnZfqn_adnZ2d@giganews.com> <11cdpo3$7e97$3@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-3.nntp.ord.giganews.com!Xl.tags.giganews.com!local-4.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 04 Nov 2026 00:17:35 +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> <mdicnZHlMZlPlXf3nZ2dnZfqnPednZ2d@giganews.com> <11cd22m$3tpfp$2@dont-email.me> <x8adnYBW_KQgjnf3nZ2dnZfqn_adnZ2d@giganews.com> <11cdpo3$7e97$3@dont-email.me> From: Ross Finlayson <ross.a.finlayson@gmail.com> Date: Tue, 3 Nov 2026 16:17:07 -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: <11cdpo3$7e97$3@dont-email.me> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID: <JWmdncGFCcoC5Hf3nZ2dnZfqnPGdnZ2d@giganews.com> Lines: 97 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-gpwJm+i+s0qF6w1/leuaLk0HkXu/ovQlgLpuQesIUBm2ZbrJ/Dr89tHWf6af/0uUjSW1uIc/aTdMBiC!XvX5KPzS8rlgwnL7AXLTuTF5xc6Lu5FoLglDCdtS4x47USfxs9f1K/XrfSztWL2jmiPbOayyp90= 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