Re: Optimizing empty functions in C

"Dave Hansen" <iddw@hotmail.com>
28 Jun 2002 18:12:06 -0400

          From comp.compilers

Related articles
[8 earlier articles]
Re: Optimizing empty functions in C wasowski@data.pl (Andrzej Wasowski) (2002-06-20)
Re: Optimizing empty functions in C mlacey@microsoft.com (Mark Lacey \[MSFT\]) (2002-06-20)
Re: Optimizing empty functions in C dnovillo@redhat.com (Diego Novillo) (2002-06-28)
Re: Optimizing empty functions in C snicol@apk.net (Scott Nicol) (2002-06-28)
Re: Optimizing empty functions in C haberg@matematik.su.se (Hans Aberg) (2002-06-28)
Re: Optimizing empty functions in C ralph@inputplus.co.uk (Ralph Corderoy) (2002-06-28)
Re: Optimizing empty functions in C iddw@hotmail.com (Dave Hansen) (2002-06-28)
Re: Optimizing empty functions in C Peter-Lawrence.Montgomery@cwi.nl (Peter L. Montgomery) (2002-06-28)
| List of all articles for this month |

From: "Dave Hansen" <iddw@hotmail.com>
Newsgroups: comp.compilers
Date: 28 Jun 2002 18:12:06 -0400
Organization: Compilers Central
References: 02-06-025 02-06-047 02-06-060
Keywords: C, optimize
Posted-Date: 28 Jun 2002 18:12:06 EDT
Keyowrds: C, optimize

On 20 Jun 2002 21:43:34 -0400, "Andrzej Wasowski" <wasowski@data.pl>
wrote:


>VBDis wrote:
>> IMO the key is "inline".
>
>Wait a moment. I meant *C* compilers not C++. Do you mean that there is
>a kind of automatic inilining employed for small functions in most of C
>compilers?
>
>andrzej
>--
>[Not that I ever saw, unless you mean preprocessor macros. -John]


I don't know about "most" compilers. It depends on the
implementation. The compiler is allowed to inline functions as long
as it behaves "as-if" it hadn't.


FWIW, the Metaware High C compiler for protected mode x86 I used two
jobs ago compiled the following file:


      static int square(int n)
      {
            return n*n;
      }


      int f(void)
      {
            return square(3);
      }


into


      f:
            mov eax, 9
            ret


Note that square is static and its address is never taken, so the
compiler didn't even bother to generate code for it.


Of course, C99 does have inline, though it's different than inline in
C++. And most C compilers don't (yet?) comply with C99.


Regards,


                                                              -=Dave
--
Change is inevitable, progress is not.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.