
Patrick B. answered 05/18/20
Math and computer tutor/teacher
These functions worked for me... I got Bloodshed Dev C++;
I do remember back in the day that The turbo C++ compiler warned
you that it cannot inline the function containing loops, if statements,
select statements, and basically any type of selection or looping statements...
not an error, just a warning that your request to inline the function is DENIED...
some compilers attempt to do it, but don't say anything if they can't;
I didn't see anything regarding either function....both returned the correct
result of 6=3!
It is safe to say that Factorial() was inlined... but we aren't sure about factorial()
as it contains an if statement; no way to tell except by reverse engineering, or
getting an assembler version of the object code and check the jump and return calls
...no thanks..
================================================
using namespace std;
#include <iostream>
inline long factorial( long N)
{
long longIntNumReturn;
if (N==1)
{
longIntNumReturn=1;
}
else
{
longIntNumReturn = N * factorial(N-1);
}
return(longIntNumReturn);
}
inline long Factorial(long N)
{
return (
(
(N==1) ? 1 : (N*Factorial(N-1))
)
);
}
int main()
{
cout << factorial(3) << endl;
cout << Factorial(3) << endl;
}