Why should I do something like this:
inline double square (double x) { return x * x; }
instead of
double square (double x) { return x * x; }
Is there a difference?
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.
The former (using
inline) allows you to put that function in a header file, where it can be included in multiple source files. Usinginlinemakes the identifier in file scope, much like declaring itstatic. Without usinginline, you would get a multiple symbol definition error from the linker.Of course, this is in addition to the hint to the compiler that the function should be compiled inline into where it is used (avoiding a function call overhead). The compiler is not required to act upon the
inlinehint.