AMD Athlon™ Processor x86 Code Optimization
Avoid Recursive Functions
66
Avoid recursive functions due to the danger of overflowing the
return address stack. Convert end-recursive functions to
iterative code. An end-recursive function is when the function
call to itself is at the end of the code.
Example 1 (Avoid):
long fac(long a)
{
if (a==0) {
return (1);
} else {
return (a*fac(a–1));
}
return (t);
}
Example 2 (Preferred):
long fac(long a)
{
long t=1;
while (a > 0) {
t *= a;
a--;
}
return (t);
}
22007E/0—November 1999
Avoid Recursive Functions
Need help?
Do you have a question about the Athlon Processor x86 and is the answer not in the manual?
Questions and answers