C99 inline semantics are often misunderstood. The inline specifier serves two purposes:
First, as a compiler hint in case of
static inlineandextern inlinedeclarations. Semantics remain unchanged if you remove the specifier.Second, in case of raw inline (ie without
staticorextern) to provide an inline definition as an alternative to an external one, which has to be present in a different translation unit. Not providing the external one is undefined behaviour, which will normally manifest as linking failure.
带有static和extern的情况下,
static inline === static
extern inline === extern
否则,和
inline === extern
C99中的inline关键字常被误解,它有两个作用:一是作为编译提示,在函数声明中;二是提供内联定义,作为外部定义的替代,外部定义必须在不同的翻译单元中给出。如果不提供外部定义,将导致未定义行为,通常表现为链接失败。
7197

被折叠的 条评论
为什么被折叠?



