By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,708 Members | 1,570 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,708 IT Pros & Developers. It's quick & easy.

inline-code

P: n/a
hi,

i have a simple question for inline code :

class x {
private:
int xx;
public:
int getXX(void){ return x; }
};

is the same like :

class x {
private:
int xx;
public:
int getXX( void );
};

inline int x::getXX( void )
{
return x;
}

or is a differenz between these code ?

thanks
Stephan
Jul 22 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
On Mon, 19 Jan 2004 16:23:48 +0100, Stephan Winter wrote:
hi,

i have a simple question for inline code :
int getXX(void){ return x; } inline int x::getXX( void ) or is a differenz between these code ?


There _may_ be a difference. The first kind of inlining is done when you
compile the code #include-ing the header file. The second is a request to
do inlining at the linking stage. Which it may or may not do.

Read your compiler and linkers documentation.

--
NPV

"the large print giveth, and the small print taketh away"
Tom Waits - Step right up

Jul 22 '05 #2

P: n/a
On Mon, 19 Jan 2004 16:23:48 +0100, Stephan Winter wrote:
hi,

i have a simple question for inline code :
[ snip inclass-definition and outclass-inline-definition ]
or is a differenz between these code ?


No, they are equivalent.

HTH,
M4

Jul 22 '05 #3

P: n/a

"Martijn Lievaart" <m@remove.this.part.rtij.nl> wrote in message
news:pa****************************@remove.this.pa rt.rtij.nl...
On Mon, 19 Jan 2004 16:23:48 +0100, Stephan Winter wrote:
hi,

i have a simple question for inline code :
[ snip inclass-definition and outclass-inline-definition ]
or is a differenz between these code ?


No, they are equivalent.


I don't think that's correct. As I understand it, the inline keyword is
actually just a suggestion/request to inline the code. It's possible that
the compiler/linker may *not* inline it. Isn't that correct?

HTH,
M4

Jul 22 '05 #4

P: n/a

"Howard" <al*****@hotmail.com> wrote in message
news:bu********@dispatch.concentric.net...

"Martijn Lievaart" <m@remove.this.part.rtij.nl> wrote in message
news:pa****************************@remove.this.pa rt.rtij.nl...
On Mon, 19 Jan 2004 16:23:48 +0100, Stephan Winter wrote:
hi,

i have a simple question for inline code :


[ snip inclass-definition and outclass-inline-definition ]
or is a differenz between these code ?


No, they are equivalent.


I don't think that's correct. As I understand it, the inline keyword is
actually just a suggestion/request to inline the code. It's possible that
the compiler/linker may *not* inline it. Isn't that correct?


But that is true for either case.
They are equivalent.
HTH,
M4


Jul 22 '05 #5

P: n/a

"Nils Petter Vaskinn" <no@spam.for.me.invalid> wrote in message
news:pa****************************@spam.for.me.in valid...
On Mon, 19 Jan 2004 16:23:48 +0100, Stephan Winter wrote:
hi,

i have a simple question for inline code :
int getXX(void){ return x; }

inline int x::getXX( void )

or is a differenz between these code ?


There _may_ be a difference. The first kind of inlining is done when you
compile the code #include-ing the header file. The second is a request to
do inlining at the linking stage. Which it may or may not do.


There isn't. And it isn't. But it is true that it mat not do the inlining.
In particular the compiler is highly likely to inline nothing at all if you
compile
for debugging.

(You may be getting confused with extern templates)
Read your compiler and linkers documentation.

--
NPV

"the large print giveth, and the small print taketh away"
Tom Waits - Step right up

Jul 22 '05 #6

P: n/a
On Mon, 19 Jan 2004 13:27:38 -0500, Howard wrote:

"Martijn Lievaart" <m@remove.this.part.rtij.nl> wrote in message
news:pa****************************@remove.this.pa rt.rtij.nl...
On Mon, 19 Jan 2004 16:23:48 +0100, Stephan Winter wrote:
> hi,
>
> i have a simple question for inline code :


[ snip inclass-definition and outclass-inline-definition ]
> or is a differenz between these code ?


No, they are equivalent.


I don't think that's correct. As I understand it, the inline keyword is
actually just a suggestion/request to inline the code. It's possible that
the compiler/linker may *not* inline it. Isn't that correct?


That is right, but the same goes for the inclass definition, so they are
equivalent. (BTW I've yet to see a linker that can do inlining, although
it makes sense).

M4
Jul 22 '05 #7

P: n/a
Howard wrote:
"Martijn Lievaart" <m@remove.this.part.rtij.nl> wrote in message
news:pa****************************@remove.this.pa rt.rtij.nl...
On Mon, 19 Jan 2004 16:23:48 +0100, Stephan Winter wrote:
> hi,
>
> i have a simple question for inline code :


[ snip inclass-definition and outclass-inline-definition ]
> or is a differenz between these code ?


No, they are equivalent.


I don't think that's correct. As I understand it, the inline keyword is
actually just a suggestion/request to inline the code. It's possible that
the compiler/linker may *not* inline it. Isn't that correct?
...


Inlining is always a suggestion regardless of how the function is
declared - outside the class definition with explicit 'inline' keyword
or inside the class definition. Both variants are indeed equivalent.

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #8

P: n/a

"Andrey Tarasevich" <an**************@hotmail.com> wrote in message
news:10*************@news.supernews.com...

Inlining is always a suggestion regardless of how the function is
declared - outside the class definition with explicit 'inline' keyword
or inside the class definition. Both variants are indeed equivalent.

--
Best regards,
Andrey Tarasevich


Ok, thanks. I learn something new here every day! :-)

-Howard
Jul 22 '05 #9

P: n/a

"Martijn Lievaart" <m@remove.this.part.rtij.nl> wrote in message
news:pa****************************@remove.this.pa rt.rtij.nl...
[SNIP]
I don't think that's correct. As I understand it, the inline keyword is
actually just a suggestion/request to inline the code. It's possible that the compiler/linker may *not* inline it. Isn't that correct?


That is right, but the same goes for the inclass definition, so they are
equivalent. (BTW I've yet to see a linker that can do inlining, although
it makes sense).

M4


AFAIK SGI's and IBM's Visual Age compiler are/were able to do such things.
Furthermore there are some other inhouse compilers that can do that job,
although it is still not very common.

Chris
Jul 22 '05 #10

P: n/a
Chris Theis wrote:
> I don't think that's correct. As I understand it, the inline keyword is
> actually just a suggestion/request to inline the code. It's possible that > the compiler/linker may *not* inline it. Isn't that correct?


That is right, but the same goes for the inclass definition, so they are
equivalent. (BTW I've yet to see a linker that can do inlining, although
it makes sense).

M4


AFAIK SGI's and IBM's Visual Age compiler are/were able to do such things.
Furthermore there are some other inhouse compilers that can do that job,
although it is still not very common.
...


This capability is not really needed for standard C++ inlining (as it is
defined in C++ language specification), since the language specification
requires source code of inline function to be available in every
translation unit where the function is used.

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.