From: "Ilya P. Ryzhenkov" Newsgroups: comp.os.msdos.djgpp Subject: Re: Will djgpp optimize recursive function calls? Date: Sun, 17 Nov 1996 12:43:47 -0800 Organization: Institute of Semiconductor Physics Lines: 30 Distribution: world Message-ID: <328F7903.5B8E@spy.isp.nsc.ru> References: <328E1F11 DOT 5F69 AT cs DOT com> Reply-To: ilya AT spy DOT isp DOT nsc DOT ru NNTP-Posting-Host: arab.isp.nsc.ru Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp 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