我在stackoverflow中读了几个关于inlineC的问题,但仍然不清楚.
static inline void f(void) {}没有实际的区别static void f(void) {}.inline void f(void) {}在C中不能像C++那样工作.它在C中如何工作?extern inline void f(void);什么?我从来没有真正inline在我的C程序中找到关键字的使用,当我在其他人的代码中看到这个关键字时,它几乎总是static inline,我认为没有区别static.
简单的问题:
给出以下程序:
#include <stdio.h>
inline void addEmUp(int a, int b, int * result)
{
if (result) {
*result = a+b;
}
}
int main(int argc, const char * argv[])
{
int i;
addEmUp(1, 2, &i);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到链接器错误...
Undefined symbols for architecture x86_64:
_addEmUp", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
看起来似乎没有费心去编译它.
它不应该是static,我不会想,基于我读过的内容:
链接器错误内联函数(因为这是在一个不同的对象,并处理2个定义而不是零)
这是一个相关的链接,但它是c ++,我认为在std C中将代码放入头文件中是不错的做法: …