Thread View: comp.lang.c
1 messages
1 total messages
Started by Tim Rentsch
Wed, 07 Oct 2026 05:14
Re: MISRA C
Author: Tim Rentsch
Date: Wed, 07 Oct 2026 05:14
Date: Wed, 07 Oct 2026 05:14
34 lines
3369 bytes
3369 bytes
Ben Bacarisse <ben@bsb.me.uk> writes: > Sorry I'm jumping in here. I don't read Usenet much these days but this > got me going. > > David Brown <david.brown@hesbynett.no> 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...
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads