Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: MISRA C
Date: Tue, 06 Oct 2026 22:14:27 -0700
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <86se2iks7g.fsf@linuxsc.com>
References: <11822bi$39m36$1@dont-email.me> <118pkkd$3gajb$1@dont-email.me> <118q3np$3e19p$2@dont-email.me> <118q63q$3l59m$1@dont-email.me> <118qftr$3nc7i$1@dont-email.me> <119473t$33192$1@dont-email.me> <119493r$33m1o$1@dont-email.me> <1194c7i$34ldb$2@dont-email.me> <1194mqo$37fnf$3@dont-email.me> <1195gqh$23uj$1@news.muc.de> <1195qr8$2aem2$1@dont-email.me> <1195u2r$16ah$1@news.muc.de> <119612d$2aem2$2@dont-email.me> <11962u0$16ah$2@news.muc.de> <1196fb8$3rdj2$1@kst.eternal-september.org> <1196l3v$1b0$1@news.muc.de> <1196nn7$3upk9$1@kst.eternal-september.org> <1197piq$8k7p$1@dont-email.me> <87o6da9yyi.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Wed, 07 Oct 2026 05:14:30 +0000 (UTC)
Injection-Info: dont-email.me; logging-data="2706486"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197IazxbTowOLoh90YluX9NtYIMvhBvFV0="; posting-host="f116a0ff36505fb6c1fca8f439768e04"
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:i/BoGkUSK3ApV4R/QRjt0fAuxk4= sha1:A7aiBOBmOoOF1qfErx/dpBCmCzc= sha256:YJrpYv9LHKgd5nL3zX4vDSXBadG+S30X281weAfUjCw= sha1:w0Q07beCTSsqDxQBNzLNl2HVY8E= sha256:LgeJvLZKpkubOZMoD6lJ/MFd6stZzhxdfdtPzK3JyKE=
Xref: csiph.com comp.lang.c:402779
Ben Bacarisse writes:
> Sorry I'm jumping in here. I don't read Usenet much these days but this
> got me going.
>
> David Brown writes:
>
>> You can implement the Ackermann function without explicit recursion, just
>> using a single loop and with allocated stacks or lists to hold the progress.
>> But you /cannot/ do so with a single allocation at the start. If you are
>> asked to calculate A(m, n), you cannot calculate an upper bound on the stack
>> size you need without calculating the function.
>
> Hmm... This is likely to confuse people. You can calculate A(m, n)
> using O(m) extra space. You can pre-allocate the space you need before
> starting the calculation. (Aside: this disregards the space needed to
> store the numbers. A(m, n) grows so large that you need extra space
> just to store the integers, but that complicates the discussion and I
> think everyone has been ignoring it in this thread anyway.)
>
> A carefully written recursive version will also use only O(m) stack, but
> here we get into problems of definition. Given that there is an
> iterative version that needs only O(m) extra storage there is obviously
> a trivial recursive version of that function that, say, just pointlessly
> calls itself once!
>
>> But with malloc() and realloc(), you are good to go!
>
> In an imaginary C with unbounded integers, you can do it with a couple
> of VLAs at the top of the function.
After seeing Waldek's post I see now what you're getting at.
Thank you for jumping in. There is always something new to
learn...