![]() |
![]() |
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.
MISRA C:2012 Rules applicable to message 1520:
| Rule-17.2 (Required) | Functions shall not call themselves, either directly or indirectly |
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index | Contents |