main.c中定义inline函数f,然后在main函数中调用。
出错:undefined reference to f
这是C标准原话:
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.
让我不明白的是,编译器总是倾向于调用external definition的函数,如果inline函数不加extern使其变成external definition,inline函数压根就没有用!!C99为什么要这样设计呢??
我找了一个帖子,不过也没有完全说清楚
http://stackoverflow.com/questions/6312597/is-inline-without-static-or-extern-ever-useful-in-c99