inline-code

S

Stephan Winter

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
 
N

Nils Petter Vaskinn

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.
 
H

Howard

Martijn Lievaart said:
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?
 
N

Nick Hounsome

Howard said:
Martijn Lievaart said:
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.
 
N

Nick Hounsome

Nils Petter Vaskinn said:
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)
 
M

Martijn Lievaart

Martijn Lievaart said:
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
 
A

Andrey Tarasevich

Howard said:
Martijn Lievaart said:
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.
 
H

Howard

Andrey Tarasevich said:
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.

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

-Howard
 
C

Chris Theis

[SNIP]
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
 
A

Andrey Tarasevich

Chris said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,416
Latest member
LionelQ387

Latest Threads

Top