How does the Delphi 2009 compiler handle recursive inline methods?

Do the “ What's wrong with built-in functions ” and “ Can a recursive function be built-in ” apply for Delphi built-in functions? Also, does anyone know how recursive inline functions are handled in Delphi?

+4
source share
1 answer

My guess is probably not so, since inline is just a suggestion, but let's find out.

Simple recursive factorial procedure:

function Factorial(const aNum: cardinal): cardinal; begin if aNum > 1 then Result := Factorial(aNum - 1) * aNum else Result := 1; end; 

Here is the call parsing:

 // fact := Factorial(5); mov eax,$00000005 call Factorial mov ebx,eax 

And analysis of the procedure itself:

 // 9: begin push ebx mov ebx,eax // 10: if aNum > 1 then cmp ebx,$01 jbe $0040ab30 // 11: Result := Factorial(aNum - 1) * aNum mov eax,ebx dec eax call Factorial imul ebx pop ebx ret // 13: Result := 1; 0040ab30: mov eax,$00000001 // 14: end; pop ebx ret 

Now we make it inline and see what is different in this case:

 // 21: fact := Factorial(5); mov eax,$00000005 call Factorial mov ebx,eax 

And the procedure itself:

 // 9: begin push ebx mov ebx,eax // 10: if aNum > 1 then cmp ebx,$01 jbe $0040ab30 // 11: Result := Factorial(aNum - 1) * aNum mov eax,ebx dec eax call Factorial imul ebx pop ebx ret // 13: Result := 1; 0040ab30: mov eax,$00000001 // 14: end; pop ebx ret 

And they both seem the same to me, so I will stick to my original hypothesis and say that they are not supported.

BTW : this is in Delphi 2009.

+10
source

All Articles