inlining functions... when ?

Started by
1 comment, last by Bullmax 21 years, 2 months ago
When should I use inline functions. I know that the function content execution must be simple and, I think, faster than the function call. Examples: pixel plotting, class accessors & mutators, etc... But do someone have a good and precise way to evaluate if a function fits to be inlined. I''m just annoyed of making modifications to my "supposed to be inlined funtion" and having recompile the whole stuff... If my functions don''t fit to be inlined, I want them to be in a "*.cpp" instead of a "*.h". /* Bullmax */ ------------- Reality has many forms : good and evil, black and white, yin and yang.
/* Bullmax */-------------Reality has many forms : good and evil, black and white, yin and yang.
Advertisement
This is how I see it. Though it might not be the best way to think of it.
It depends on the function. If it was something like to add a couple of numbers together then you would use an inline, because there wouldn''t be a lot of point jumping for a job so small. If it was a more complex function then you''d probably wouldn''t use inline.

Inline functions are like writting the code in the function where you called it, instead of a jump like a normal function. They are similar to Macros in C.

slip
www.ice-d.com
Don''t worry about inlining until your program is complete.

What functions can be inlined and what happens when inlining fails is compiler-dependent - check the documentation.

As a rule of thumb, any kind of loop, recursion or taking the address of the function will inhibit inlining.

[ 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 ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement