[chbot] GCC and recursion

Volker Kuhlmann list57 at top.geek.nz
Fri Mar 29 23:15:24 GMT 2024


> 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.

I agree that that should have nothing to do with gcc, although it is
possible that gcc has quite a few bugs affecting correct code generation
for some µC cores. Those are gcc version dependent too.

What architecture are you generating code for? Is your assembler running
on x86? It's safe to assume for that that crashes are caused by your
code, not gcc.

Recursive programming relies on having a reliable exit condition, taken
before resources like stack run out. An easy way to check is to write
out the parameters for each call on a single line, one line per call,
and any unrestrained criteria show up at the bottom of the screen.

> It could be that the compiler is not generating re-entrant code.

Not for x86. More likely a variable which changes with each call is not
local. A compiler bug, if it's for esoteric cores, would still be down
on my list.

Why don't you just compile for x86 and test in a high-resource
environment first?

Volker

-- 
Volker Kuhlmann
http://volker.top.geek.nz/	Please do not CC list postings to me.



More information about the Chchrobotics mailing list