I know that inline is a hint or request to the compiler and is used to avoid function call overheads.
So, on what basis one can determine whether a function is a candidate for inlining or not?
In which case one should avoid inlining?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Avoiding the cost of a function call is only half the story.
do:
inlineinstead of#defineinline: faster code and smaller executables (more chances to stay in the code cache)don’t:
when developing a library, in order to make a class extensible in the future you should:
Remember that the
inlinekeyword is a hint to the compiler: the compiler may decide not to inline a function and it can decide to inline functions that were not markedinlinein the first place. I generally avoid marking functioninline(apart maybe when writing very very small functions).About performance, the wise approach is (as always) to profile the application, then eventually
inlinea set of functions representing a bottleneck.References:
EDIT: Bjarne Stroustrup, The C++ Programming Language:
EDIT2: ISO-IEC 14882-1998, 7.1.2 Function specifiers