Skip to main content
gamedev.net
🔒 Locked

Inline functions?

Started by _damN_ Apr 8, 2009 at 12:53 AM 6 replies 1k views
Original Post
_damN_
_damN_
Quick question... Are inline functions good? And when should i rather use inline functions when programming... Thanks.
Bargaust
Bargaust
Quick (related) question... Is the typical C++ compiler (in my case, VC++) clever enough to automatically inline a very simple accessor method (that just returns a private member variable), or would I need to specify 'inline' myself?
Wan
Wan
Quote:
Original post by Bargaust
Is the typical C++ compiler (in my case, VC++) clever enough to automatically inline a very simple accessor method (that just returns a private member variable), or would I need to specify 'inline' myself?

It should be, yes. You could give a 'hint' to the compiler by declaring it inline (or even force it by using __forceinline), but VC should be smart enough to figure that out for itself.
Red Ant
Red Ant
Not necessarily. It's still just a suggestion to the compiler.
Mantear
Mantear
I tend to use 'inline' as a hint to anyone else reading the code rather than the compiler since, as I understand it, the compiler will pretty much do what it wants anyways. Your compiler optimization settings (size vs speed, etc) probably have a bigger influence on whether a function is actually inlined or not than using the keyword in the source code.
loufoque
loufoque
Unlike what you may think, "inline" is not just a hint to the compiler.
It's also necessary when you define a function in a header, otherwise you get multiple definitions issues.

Note all member functions defined in the class definition are inline implicitly.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.