![]() |
![]() |
1520 | ![]() |
||||
![]() | |||||||
| CMA maintenance checks | |||||||
A group of functions have been identified which appears to form a recursive sequence. In general most recursive functions can be replaced with a stack and loop and in most cases the performance and scalability of the code will be improved. Amongst others, recursive functions have two main drawbacks:
int recursiveFactorial(int i)
{
if (1 == i)
{
return i;
}
else
{
return i * recursiveFactorial (i - 1);
}
}
int loopFactorial(int i)
{
int result = 1;
for (; i > 1; --i)
{
result *= i;
}
return result;
}
Even in these small examples above, for large values of 'i', the recursive implementation can take up to twice as long as the non recursive version.
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |