Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #402451
| From | bart <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: MISRA C |
| Date | 2026-09-28 13:07 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <119dla5$2af5o$1@dont-email.me> (permalink) |
| References | (12 earlier) <1195qr8$2aem2$1@dont-email.me> <1195u2r$16ah$1@news.muc.de> <119612d$2aem2$2@dont-email.me> <11962u0$16ah$2@news.muc.de> <119dhqt$1uucd$1@dont-email.me> |
On 28/09/2026 12:08, Janis Papanagnou wrote: > On 2026-09-25 17:10, Alan Mackenzie wrote: >> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote: >>> On 2026-09-25 15:48, Alan Mackenzie wrote: >>>> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote: >> >> [ .... ] >> >>>>> WRT Dude's statement it should be mentioned that a recursive algorithm >>>>> can be transformed to an iterative one, so if iterative algorithms >>>>> would have the property to be _decidable_ to finish - actually, they >>>>> are not - we could also say the same for a recursive one. >> >>>> Recursion can often be programmed iteratively in practice. In theory, >>>> there are recursively defined functions which grow too quickly with >>>> increasing argument to be definable (or programmable) without >>>> recursion. >> >>> Have you functions like fib() in mind? - Despite they are cascaded >>> recursion you can create iterative ones. - But it's simpler; just >>> recognize that a recursion is using an implicit stack, so you can >>> write it in iterative form with an explicit stack. Even an extreme >>> function like Ackermann (which is more demanding) is not exempt to >>> that principle. - Or do you disagree? (Then please explain - best >>> with an example you may have in mind.) >> >> Yes, it was the Ackermann function I had in mind (though I'd forgotten >> its name). It's a function of two natural number arguments. Simply >> making both arguments the same gives a function of one argument. >> >> [...] >> >> This function can't be calculated iteratively, since there's no >> non-recursive way of calculating how big the requisite static arrays >> would have to be. Or something like that. > > Franky, I'm too lazy now to derive the iterative form myself. But > if you're not convinced by the principle considerations it's fairly > easy to ask an AI to create some C-code, verify that it has no > recursive calls, and check its results. - The code that the AI had > provided to me seems to work well.[*] Actually any recursive code in C can be implemented without recursion. You don't have to change the source code. Example: c:\cx>cc -r ack Compiling ack.c to ack.(run) A= 8189 c:\cx>cc -i ack Compiling ack.c to ack.(int) A= 8189 The first invocation runs native code that uses actual recursive calls with a hardware stack. The second invocation interprets it. It uses a software stack, and an iterative loop to execute the bytecode instructions. The difference from your machine-generated Ackermann is that that was specific to the task, but my approach can run C programs in general without a stack. (It also uses a hardware stack for some features of the interpreter, but your version uses one too for the function calls.)
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
MISRA C (was: buckle-up ....) Alan Mackenzie <acm@muc.de> - 2026-09-25 10:01 +0000
Re: MISRA C Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-09-25 14:52 +0200
Re: MISRA C Alan Mackenzie <acm@muc.de> - 2026-09-25 13:48 +0000
Re: MISRA C Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-09-25 16:39 +0200
Re: MISRA C Alan Mackenzie <acm@muc.de> - 2026-09-25 15:10 +0000
Re: MISRA C bart <bc@freeuk.com> - 2026-09-25 16:57 +0100
Re: MISRA C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-09-25 11:42 -0700
Re: MISRA C Alan Mackenzie <acm@muc.de> - 2026-09-25 20:21 +0000
Re: MISRA C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-09-25 14:05 -0700
Re: MISRA C David Brown <david.brown@hesbynett.no> - 2026-09-26 08:43 +0200
Re: MISRA C Alan Mackenzie <acm@muc.de> - 2026-09-26 17:55 +0000
Re: MISRA C Ben Bacarisse <ben@bsb.me.uk> - 2026-10-03 23:55 +0100
Re: MISRA C David Brown <david.brown@hesbynett.no> - 2026-10-04 16:10 +0200
Re: MISRA C Ben Bacarisse <ben@bsb.me.uk> - 2026-10-05 01:22 +0100
Re: MISRA C David Brown <david.brown@hesbynett.no> - 2026-10-05 07:59 +0200
Re: MISRA C Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-10-05 01:23 -0700
Re: MISRA C Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-10-05 01:24 -0700
Re: MISRA C antispam@fricas.org (Waldek Hebisch) - 2026-10-05 09:02 +0000
Re: MISRA C Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-10-05 12:07 +0200
Re: MISRA C Ben Bacarisse <ben@bsb.me.uk> - 2026-10-05 15:29 +0100
Re: MISRA C antispam@fricas.org (Waldek Hebisch) - 2026-10-05 20:29 +0000
Re: MISRA C Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-10-06 22:13 -0700
Re: MISRA C Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-10-06 22:14 -0700
Re: MISRA C Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-09-27 10:52 -0700
Re: MISRA C Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-09-28 13:08 +0200
Re: MISRA C bart <bc@freeuk.com> - 2026-09-28 13:07 +0100
Re: MISRA C David Brown <david.brown@hesbynett.no> - 2026-09-28 14:08 +0200
Re: MISRA C Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-09-28 14:28 +0200
Re: MISRA C Alan Mackenzie <acm@muc.de> - 2026-09-28 12:17 +0000
Re: MISRA C Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-09-28 14:40 +0200
Re: MISRA C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-09-30 10:21 -0700
Re: MISRA C Alan Mackenzie <acm@muc.de> - 2026-09-30 19:57 +0000
Re: MISRA C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-09-30 13:09 -0700
Re: MISRA C David Brown <david.brown@hesbynett.no> - 2026-10-01 08:47 +0200
Re: MISRA C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-10-01 15:18 -0700
Re: MISRA C Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-27 04:58 +0800
Re: MISRA C David Brown <david.brown@hesbynett.no> - 2026-09-25 17:02 +0200
Re: MISRA C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-09-26 15:37 -0700
csiph-web