【发布时间】:2015-06-30 02:38:18
【问题描述】:
我目前正在将软件项目的一些与操作系统相关的功能从 Linux 移植到 FreeBSD。因此,如果在 FreeBSD 10.1 上定义了 _POSIX_C_SOURCE=200809L,我使用 getpagesize 识别出以下问题。
我创建了一个小测试程序
#include <stdio.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int i = getpagesize();
return 0;
}
如果我编译是使用
cc test.c -o test
它编译时没有任何警告。但是,如果我定义 _POSIX_C_SOURCE=200809L(我在代码的其他部分需要的 getline 函数的正确 POSIX 定义的结果)我得到:
cc test.c -D_POSIX_C_SOURCE=200809L
test.c:5:10: warning: implicit declaration of function 'getpagesize' is invalid in C99 [-Wimplicit-function-declaration]
int i = getpagesize();
^
尽管我在getpagesize 的手册页中提到了unistd.h。如何使用仍然定义的_POSIX_C_SOURCE 使代码编译没有警告?
【问题讨论】: