It is for micromanagement fanatics. The compiler is free to ignore the
inline, and it usually does if you compile for space optimisation and
call the function from two or more different places.
If you want your compiler to decide, use static inline.
If you want it _always_ inlined, use macros.
Even if you use static without inline, the compiler can inline anyway.
(For that reason, compilers should really treat inline seriously and
"do it", otherwise what is it for?)
In one recent project, I detect what kind of support there is for inline
using a shell script that compiles code samples. It prepares a suitable
"#define INLINE ..." line in a "config.h" header.
It will detect whether the static keyword is required or not by doing
linkage tests (is there a clash if the same inline function goes into
two translation units).
With gcc in C90 mode (-ansi) it turns out to be:
#define INLINE static __inline__
If I configure to build build the program using g++, then it's just "inline".
The shell code looks like this (but isn't the entire logic because it relies on
some rules in a makefile compile and which link a single program out of
conftest1.c and conftest2.c).
printf "Checking how to declare inline functions ... "
if [ -z "$inline" ] ; then
for inline in \
"inline" "static inline" "extern inline" \
"__inline__" "static __inline__" "extern __inline__" \
"static"
do
cat > conftest1.c <<!
$inline int func(void)
{
return 0;
}
int main(void)
{
return func();
}
!
cat > conftest2.c <<!
$inline int func(void)
{
return 0;
}
!
rm -f conftest2
if ! $make conftest2 > conftest.err 2>&1 ; then
continue
fi
break
done
fi
printf '"%s"\n' "$inline"
printf "#define INLINE $inline\n" >> config.h