delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/04/08/05:15:31

Date: Sat, 8 Apr 2000 05:55:20 +0600 (LKT)
From: Kalum Somaratna aka Grendel <kalum AT lintux DOT cx>
X-Sender: root AT darkstar DOT grendel DOT net
To: djgpp AT delorie DOT com
Subject: Re: about compiler or linker
In-Reply-To: <3A4F7E81.C767B4B@caresystems.com.au>
Message-ID: <Pine.LNX.4.10.10004080547160.2396-100000@darkstar.grendel.net>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Mon, 1 Jan 2001, leon wrote:

> 
> also about inline methods - if one declares a method inline - how does
> the compiler know - where to get source code from (since usually the
> client of a class only includes header files and it is possible to
> define inline method in source files).

Well the compiler knows where to get the inlined function from because the
inlined function should be defined in a header file. So when the header
file is included by a source (.cpp) file which references the inlined
function the compiler will substitute the function body (which it allready
knows about as it read it in the header file) whereever it is necessary in
the source file.


//example header file foo.h

inline void test()
{
 //your code here

}

now there is a fill called foo.c 
// file foo.c
#include "foo.h"

//now the compiler has read the  foo.h and is aware of the inlined test
function

void main()
{
 test(); //the compiler will replace this with the inlined function
//but if i the inlined function was not in the header file then the
//compiler would never know...

}

 
> Would then the linker try and introduce source code to objects when
> linking or what?

AFAIK inline routines cannot be implemented in a source file and then
refrenced in another source file.


Inline functions can be in the source file, but then they if they are to
be inlined properly then they have to be referenced in the _same_ source
file..

Grendel

Hi, I'm a signature virus. plz set me as your signature and help me spread
:)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019