Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

_elmo

inline functions

This topic is 5738 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know where to use the inline keyword, but what is the meaning of an inline function...? Makes this the function faster or does it take less memory...? Please can anyone tell me the meaning of the inline keyword, and when to use it...?! Thanx... _elmo nieuwe schoenen...

Share this post


Link to post
Share on other sites
Advertisement
The inline keywoard does exactly what it says it does, inlines.
e.g:


inline void PrintHello()
{
cout << "Hello" << endl;
}

int main()
{
PrintHello();
}

// Becomes when compiling
int main()
{
cout << "Hello" << endl;
}


It''ll be a tad faster in that that it eliminates the function call (very smal amount of time, but can be important if called offten). The bad thing with it is that the code gets longer, e.g bigger exes.

Share this post


Link to post
Share on other sites
It''s basically the C++ version of a C macro, meaning that it ideally incurs no function call overhead (that is, its text is pasted into the calling code, if the compiler does inline it), but with considerable improvements: Type safety, for one thing, and for another, it''s a real function, so you can do things like recursion (though your compiler might not inline a recursive function - it makes sense only if it can deduce the recursion depth at compile time, and it is not too great) and taking its address.

Share this post


Link to post
Share on other sites
But remember, the inline keyword is a hint, not a request. The compiler can choose not to inline the function if it doesn''t want to.

I don''t have a signature

Share this post


Link to post
Share on other sites
Sometimes the inline function is used in classes... Will this means that the whole class is placed where the function is called???

class AClass {
...
public:
inline void doSomething() {
i++;
}
};


int main(void) {
AClass *aclass = new AClass();

aclass->doSomething();

return 0;
}

Share this post


Link to post
Share on other sites
quote:
Original post by _elmo
Sometimes the inline function is used in classes... Will this means that the whole class is placed where the function is called???



No, still only the member function. And anyway, you *already* have an instance of the class (in your case aclass).

Also, know that member functions fully defined in the body of the class (i.e. with the code for the function written within the class itself), are implicitely declared inline. The keyword is redundant.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!