Mail Archives: djgpp/1996/11/17/08:22:59
John M. Aldrich wrote:
>
> I have read in some detail the gcc docs on optimization flags. As I
> understand it, if gcc detects a recursive call, it will NOT inline the
> function that uses it. It will still optimize the function itself, but
> will never convert it into inline code.
>
> For more information, look in the gcc docs under Invoking GCC |
> Optimize.
Hmmmm.... It's not true perfectly ... Consider :
inline unsigned long fact(unsigned long i) /* I don't know if it will be
inlined without inline keyword, but i hope */
{
return (i<2)?i:fract(i-1)*i;
}
void main()
{
fract(0); fract(1); fract(2);
}
and compile this with gcc -O3 -o test.s test.c -S
and look into resulting test.s file
You'll see, that GCC DO optimizes (inline), but only for the FIRST call.
so you will actually get
fract(x-1)*x for the call like fract(x) and a constant if you use
frac(0) or fract(1)
Sincerely yours, Ilya
-----------------------------------------------------------------------------
mailto://ilya AT spy DOT isp DOT nsc DOT ru
http://spy.isp.nsc.ru
- Raw text -