我不明白为什么函数getpagesize在使用c18版本的gcc时给出了隐式声明函数的警告。
gcc test.c -Wall -std=c18
隐式声明函数'getpagesize'[-Wimplicit-function-declaration]
'getpagesize'的嵌套extern声明[-Wnested-externs]
int BLOCKSIZE = getpagesize();
这是我包含的文件:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <stdint.h>
#include <errno.h>
使用-std=cXX
而不是-std=gnuXX
禁用一堆正常定义的feature test macros,包括提供getpagesize()
的那些。从它的man page(假设你使用的是linux):
glibc的功能测试宏要求(参见feature_test_macros(7)):
getpagesize(): Since glibc 2.19: _DEFAULT_SOURCE || ! (_POSIX_C_SOURCE >= 200112L) From glibc 2.12 to 2.19: _BSD_SOURCE || ! (_POSIX_C_SOURCE >= 200112L) Before glibc 2.12: _BSD_SOURCE || _XOPEN_SOURCE >= 500
因此,在包含任何头文件之前,必须将适当的值定义为适当的值。或者只是使用-std=gnu18
。
编辑:此外,由于getpagesize()
已过时且不标准,请考虑使用POSIX标准sysconf(_SC_PAGESIZE)
。