我果然不懂 C 啊。

from gcc-4.2.info:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
5.34 An Inline Function is As Fast As a Macro

<..snipped..>

If you specify both `inline' and `extern' in the function definition,
then the definition is used only for inlining. In no case is the
function compiled on its own, not even if you refer to its address
explicitly. Such an address becomes an external reference, as if you
had only declared the function, and had not defined it.

This combination of `inline' and `extern' has almost the effect of a
macro. The way to use it is to put a function definition in a header
file with these keywords, and put another copy of the definition
(lacking `inline' and `extern') in a library file. The definition in
the header file will cause most calls to the function to be inlined.
If any uses of the function remain, they will refer to the single copy
in the library.

Since GCC 4.3 will implement ISO C99 semantics for inline functions,
it is simplest to use `static inline' only to guarantee compatibility.
(The existing semantics will remain available when `-std=gnu89' is
specified, but eventually the default will be `-std=gnu99'; that will
implement the C99 semantics, though it does not do so in versions of
GCC before 4.3\. After the default changes, the existing semantics will
still be available via the `-fgnu89-inline' option or the `gnu_inline'
function attribute.)

GCC does not inline any functions when not optimizing unless you
specify the `always_inline' attribute for the function, like this:

/* Prototype. */
inline void foo (const char) __attribute__((always_inline));

So, consider the following program:

gcctest.c:

1
2
3
4
5
6
7
#include "inline.h"

int main()
{
puts(externinline());
return 0;
}

inline.h:

1
2
3
4
__inline__ extern char *externinline()
{
return "inline";
}

lib.c:

1
2
3
4
char *externinline()
{
return "extern";
}

The behavior of the executables will be different with or without the -O option of gcc. Compile it without -O, the program will print “extern”. Compile it with -O, the program will print “intern”.