inline reference:
https://blog.csdn.net/zqixiao_09/article/details/50877383
gcc8.3 必须声明,不然报错, undefined reference to `xxx’
$ make test && ./test
cc test.c -o test
/tmp/ccLJDAHG.o: In function `main':
test.c:(.text+0x25): undefined reference to `dbtest'
collect2: error: ld returned 1 exit status
make: *** [<builtin>: test] Error 1
[yumwang@hz72-12-rhel8-oms test]$ gcc --version
gcc (GCC) 8.3.1 20191121 (Red Hat 8.3.1-5)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//函数定义为inline即:内联函数
//char* dbtest(int a);//必须声明,不然报错
inline char* dbtest(int a)
{
return (a % 2 > 0) ? "奇" : "偶";
}
int main(int argc, char* argv[])
{
int i = 0;
for (i=1; i < 100; i++)
{
printf("i:%d 奇偶性:%s \n", i, dbtest(i));
}
return 0;
}
gcc4.8不用声明可直接编译
gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
inline char* dbtest(int a)
{
return (a % 2 > 0) ? "奇" : "偶";
}
int main(int argc, char* argv[])
{
int i = 0;
for (i=1; i < 100; i++)
{
printf("i:%d 奇偶性:%s \n", i, dbtest(i));
}
return 0;
}