Consider the classic way of defining a factorial function:
#include <stdio.h>
__attribute__((always_inline)) inline int factorial(int n)
{
if (n == 1){
return 1;
} else {
return n * factorial(n - 1);
}
}
int main()
{
printf("value %d", factorial(7/*guaranteed to not overflow int*/));
}
I'm forcing my compiler (gcc) to inline the factorial function. That should cause a problem. gcc is ignoring my force inline without error. Is this expected?