【发布时间】:2010-07-28 16:51:26
【问题描述】:
这个简单的 .c 文件:
#include <unistd.h>
void test() {
char string[40];
gethostname(string,40);
}
...正常编译时,工作正常:
$ cc -Wall -c -o tmp.o tmp.c
$
...但是在 C99 模式下编译时,会给出警告:
$ cc -Wall -std=c99 -c -o tmp.o tmp.c
tmp.c: In function `test':
tmp.c:5: warning: implicit declaration of function `gethostname'
$
生成的 .o 文件很好,并且链接工作正常。我只是想摆脱警告。我可以通过将声明放在我自己的 .h 文件中以一种 hacky 方式实现这一点。
C99 的什么意思是 unistd.h 中的声明不被包含在内? 能否在不放弃 C99 的优点的情况下克服这一点?
我发现其他标准库也存在同样的问题。
【问题讨论】: