Ben says:
Use INLINE_HEADER in .h files
Use INLINE in .c files
Never use `inline' in the source code
Never use `static' together with `inline' since inline already
implies internal linkage
This stuff is tricky.
gcc info docs have this to say:
Note that in C and Objective C, unlike C++, the `inline' keyword
does not affect the linkage of the function.
The upcoming C standard
http://www.dkuug.dk/JTC1/SC22/ introduces the
`inline' keyword into the C language
References (Grab 'em with `wget -r' before they become standards and
disappear forever)
http://osiris.dkuug.dk/JTC1/SC22/WG14/www/docs/
http://www.maths.warwick.ac.uk/cpp/pub/wp/html/cd2/
6.5.4 Function specifiers
Syntax
[#1]
function-specifier:
inline
Constraints
[#2] Function specifiers shall be used only in the
declaration of an identifier for a function.
[#3] An inline definition (see below) of a function with
external linkage shall not contain a definition of an object
with static storage duration that can be modified, and shall
not contain a reference to an identifier with internal
linkage.
[#4] The inline function specifier shall not appear in a
declaration of main.
Semantics
[#5] A function declared with an inline function specifier
is an inline function. Making a function an inline function
suggests that calls to the function be as fast as possible
by using, for example, an alternative to the usual function
call mechanism known as ``inline substitution''.101 The
__________
101. Inline substitution is not textual substitution, nor
does it create a new function. Therefore, for example,
the expansion of a macro used within the body of the
Language 135
Working Draft, 1997-11-21, WG14/N794 J11/97-158
extent to which such suggestions are effective is
implementation-defined.102
[#6] Any function with internal linkage can be an inline
function. For a function with external linkage, the
following restrictions apply. If a function is declared
with an inline function specifier, then it shall also be
defined in the same translation unit. If all of the file
scope declarations for a function in a translation unit
include the inline function specifier without extern, then
the definition in that translation unit is an inline
definition. An inline definition does not provide an
external definition for the function, and does not forbid an
external definition in another translation unit. An inline
definition provides an alternative to an external
definition, which a translator may use to implement any call
to the function in the same translation unit. It is
unspecified whether a call to the function uses the inline
definition or the external definition.
Examples
[#7] The declaration of an inline function with external
linkage can result in either an external definition, or a
definition available for use only within the translation
unit. A file scope declaration with extern creates an
external definition. The following example shows an entire
translation unit.
____________________________________________________________
function uses the definition it had at the point the
function body appears, and not where the function is
called; and identifiers refer to the declarations in
scope where the body occurs. Similarly, the address of
the function is not affected by the function's being
inlined.
102. For example, an implementation might never perform
inline substitution, or might only perform inline
substitutions to calls in the scope of an inline
declaration.
136 Language
Working Draft, 1997-11-21, WG14/N794 J11/97-158
inline double fahr(double t)
{
return (9.0 * t) / 5.0 + 32.0;
}
inline double cels(double t)
{
return (5.0 * (t - 32.0)) / 9.0;
}
/* Creates an external definition. */
extern double fahr(double);
double convert(int is_fahr, double temp)
{
/* A translator may perform inline substitutions. */
return is_fahr ? cels(temp) : fahr(temp);
}
[#8] Note that the definition of fahr is an external
definition because fahr is also declared with extern, but
the definition of cels is an inline definition. Because
there is a call to cels, an external definition of cels in
another translation unit is still required by 6.7.
From the inline proposal:
This proposal adds the inline keyword to Standard C in such
a way that it can be implemented with existing linker tech-
nology and also is compatible with C++. This is achieved by
requiring that one and only one of the translation units
25 containing the definition of an inline function be specified
as the one that provides an external definition for the
function. Because that specification consists simply of a
declaration that lacks the inline keyword, it will also be
accepted by a C++ translator.
30 This proposal does extend the C++ specification in two ways.
First, if a function is declared inline in one translation
unit, it need not be declared inline in every other transla-
tion unit. This allows, for example, a library function
that is to be inlined within the library but to be available
35 only through an external definition elsewhere. (The alter-
native of using a wrapper function for the external function
both requires an additional name and may adversely impact
performance, if a translator does not actually do inline
substitution.)
40 Second, the requirement that all definitions of an inline
function be ``exactly the same'' is replaced by the require-
ment that the behavior of the program should not depend on
- 1 -
30 May 1997 Inlining Proposal, ReviWG14/N709 (J11/97-072)
whether a call is implemented with a visible inline defini-
tion or the external definition of a function. This allows
an inline definition to be specialized for its use within a
particular translation unit. For example, the external
5 definition of a library function might include some argument
validation that is not needed for calls made from other
functions in the same library.
These extensions do offer some advantages, and programmers
who are concerned about compatibility can simply abide by
10 the stricter C++ rules. Nevertheless, the extensions are
not central to the proposal and the C++ rules could easily
be substituted.
Still reading??? For the masochists, here are excerpts from the C++
standard:
2 A function declaration (_dcl.fct_, _class.mfct_, _class.friend_) with
an inline specifier declares an inline function. The inline specifier
indicates to the implementation that inline substitution of the func-
tion body at the point of call is to be preferred to the usual func-
tion call mechanism. An implementation is not required to perform
this inline substitution at the point of call; however, even if this
inline substitution is omitted, the other rules for inline functions
defined by this subclause shall still be respected.
3 A function defined within a class definition is an inline function.
The inline specifier shall not appear on a block scope function
declaration.2)
4 An inline function shall be defined in every translation unit in which
it is used and shall have exactly the same definition in every case
(_basic.def.odr_). [Note: a call to the inline function may be
_________________________
2) The inline keyword has no effect on the linkage of a function.
encountered before its definition appears in the translation unit. ]
If a function with external linkage is declared inline in one transla-
tion unit, it shall be declared inline in all translation units in
which it appears; no diagnostic is required. [Note: a static local
variable in an extern inline function always refers to the same
object. ]