ben said:
Ok, now, under what circumstances should I flag the keyword inline?
What are the likely candidates for inlining?
All of them.
By now, it should be clear to you that
[automatic] inlining isn't really about optimization.
It's about encouraging *functional decomposition*
by assuring performance conscious programmers that
it isn't necessary to inline function *manually*.
The 'inline' qualifier is about *linkage* not optimization.
It tells the compiler to assure the link editor
that there is only *one* function definition
regardless of how many times the function definition
appears in object files that are linked together.
I try to make *all* functions inline functions
and let my optimizing compiler decide
which ones should actually be inline'd.
You need to ask yourself a question,
"Do I really care about performance?"
If you do, you will probably want to use
as many inline function definitions as possible.
You might consider taking advantage of both
inline *and* external function definitions:
#ifndef GUARD_FILE_H
#define GUARD_FILE_H 1
#ifdef EFINE_INLINE
inline
double f(double x) {
return x*(x + 2.0) + 1.0;
}
#else //EFINE_INLINE
double f(double x);
#endif//EFINE_INLINE
#endif//GUARD_FILE_H
#undef EFINE_INLINE
#include "file.h"
double f(double x) {
return x*(x + 2.0) + 1.0;
}
g++ -DEFINE_INLINE -Wall -ansi -pedantic -O3 -c file.cc
nm --demangle file.o
00000000 T f(double)
This allows your inline and external function definitions
to coexist peacefully.
Use the -DEFINE_INLINE option only after you have finished
testing and debugging all of your code.
This will speed up the program development cycle
and allow you to optimize your code just before deployment.