Are recursive functions not allowed in C++?

So I have a simple recursive function that returns the number of places to the left of the decimal point of a float, it looks like this:

int32 CalcTenPlaces(float Num)
{
	if (Num > 10)
	{
		return CalcTenPlaces(Num / 10) + 1;
	}

	return 1;
}

When I try to build my project with this function in it, I get this error: “error C4718: ‘CalcTenPlaces’ : recursive call has no side effects, deleting.” I looked it up, and according to this, I should only get that error if the recursive function call do anything which would overflow the stack. The thing is, I tested an identically written function in Steel Bank Common Lisp on my ARM processor Chromebook with less than a 16th of the RAM on the machine that I develop for, and not even ridiculously big values would overflow the stack, values that can’t even be stored in an int32 (the last value I tested was 11298 digits long according to the function). So why doesn’t it work in UE4? Are recursive functions not allowed in UE4 C++, is this function actually likely to overflow the stack in UE4? I rewrote the function to calculate the value using iteration, I am just curious at this point.

The error tells you, that you don’t use the return value of the function. Since you don’t care about the return value and the function has no side effects, the compiler can savely delete the function call. See the example:

void func2(void)
{
func(10);  // deleted; no side effects and return value used
}

So the problem is not the recursion, but that you never do something with the return value.

Try doing something with the return value (e.g. printing to stdout) and see if the error persists.

I can’t believe that I didn’t realize I hadn’t done anything with the value my function call returned. I must be more tired than I thought. Thanks so much for the help!