[chbot] Chchrobotics Digest, Vol 198, Issue 10 GCC and recursion
Bevin Brett
bevin_brett at hotmail.com
Tue Apr 2 13:29:46 BST 2024
The alternative to recursion is either a linked list, a fixed size array, or a growing array
In RPN evaluation, the code often looks like this, because you don't need the full power and cost of recursion
ops : array of operators
stack : stack of operands
top = 0
for op in instructionStream do
caseOf nOperands(op.code)
alt add:
stack[top - 1] += stack[top]
top = top - 1
alt int:
top = top+1
stack[top] = op.int
...
Don't forget to check for malformed expressions, which could result in h/w stack corruption due to indexing outside 'stack'
/Bevin
________________________________
...
I am building an RPN expression evaluator for the uCPU assembler; I
can't see any other way to go other than to use recursion to do the
nested processing that I wish.
Currently using "gcc version 12.2.0 (MinGW-W64 x86_64-ucrt-posix-seh,
built by Brecht Sanders)"
The first call of the recursed function worked fine, but crashes upon exit.
It could be that the compiler is not generating re-entrant code. The
only switch I have used is -O0 to disable compiler optimization.
Are there any other switches for GCC that I need to use/be aware of ?
Thanks, Mark
...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20240402/df7230aa/attachment.html>
More information about the Chchrobotics
mailing list