delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/04/17/20:50:22

Date: Tue, 18 Apr 2000 06:11:53 +0600 (LKT)
From: Kalum Somaratna aka Grendel <kalum AT lintux DOT cx>
X-Sender: root AT darkstar DOT grendel DOT net
To: leon <Leon AT caresystems DOT com DOT au>
cc: djgpp AT delorie DOT com
Subject: Re: about compiler or linker
In-Reply-To: <32C920E8.3F3ADB44@caresystems.com.au>
Message-ID: <Pine.LNX.4.10.10004180600000.2110-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 Wed, 1 Jan 1997, leon wrote:

> Kalum Somaratna aka Grendel wrote:
> > 
> > On Mon, 1 Jan 2001, leon wrote:
> > 
> > Well the compiler knows where to get the inlined function from because the
> > inlined function should be defined in a header file. 
> 
> huh?!
> 
> so what about this then:
> 
> //the .h file
> class Some
> {
> 	public:
> 		Some();
> 		~Some();
> 		inline void Method();
> };
> 
> //the .cpp file
> Some::Some()
> {
> 	;
> }
> Some::~Some()
> {
> 	;
> }
> void Some::Method()
> {
> 	;
> }
> 
> now if some class uses Some.h file - it will NOT contain the source code
> definition of Method!

Yes...and therefore the Method function won't be inlined in the other
class. It would be replace by just a normal function call with all the
pushes and pops etc....

So if you *really* wan't it to be inlined you have 2 options but both have
to be done in the header (some.h) file

1'st method,

Just put the function body in the class

 //the .h file
 class Some
 {
 	public:
 		Some();
 		~Some();
 		inline void Method()
		{

		//your code will go hear

		}

 };
//end of header

Then as you can see if some.h is included by another class that class has
*acess* to the *code* of the Method function since it is in the header
file. I hope I am clear if not please tell me..

2'd  way of doing it is


 //the .h file
 class Some
 {
 	public:
 		Some();
 		~Some();
 		inline void Method();
 };

inline void Some::Method()
{


}

//end of the header file.....


So as you can see the Method function is defined not in the class body
but *still* in the *header* file. So this will also work...

So any module or class that includes some.h can inline the method function
because as before it has access to the Method functions code..

But If the Method functions was in the source (some.cpp) then the above
won't be possible.

Say there is a class called some1 which include some.h..now if the code
for Method is in some.c how is the compiler suppose to inline it (the
compiler hasn't read some.c and it doesn't know the code....)


I hope This is clear,

Best Wishes,

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