一个关于函数声明的奇怪问题
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
...
if(len != pwrite(fd, buf, len, offset))
{
...
}
...
}
我查过了pwrite()是在unistd.h里面声明的,编译时加了-Wall,就有: implicit declaration of function 'pwrite',去掉-Wall编译就没有任何警告,请问怎么解决?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
NAME
pread, pwrite - read from or write to a file descriptor at a given offset
SYNOPSIS
#define _XOPEN_SOURCE 500
#include <unistd.h>
ssize_t pread(int fd, void *buf, size_t count, off_t offset);
ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
DESCRIPTION
pread() reads up to count bytes from file descriptor fd at offset offset (from the start of the file) into the
buffer starting at buf. The file offset is not changed.
pwrite() writes up to count bytes from the buffer starting at buf to the file descriptor fd at offset offset. The
file offset is not changed.
The file referenced by fd must be capable of seeking.
RETURN VALUE
On success, the number of bytes read or written is returned (zero indicates that nothing was written, in the case
of pwrite(), or end of file, in the case of pread), or -1 on error, in which case errno is set to indicate the
error.
ERRORS
pread() can fail and set errno to any error specified for read(2) or lseek(2). pwrite() can fail and set errno to
回复 2# cugb_cat
2楼的大虾好像没明白我的意思,我说过了:我知道unistd.h里面有该函数声明,我代码里面也包含了该头文件,但加-Wall编译仍然有警告
#define _XOPEN_SOURCE 500
还是一样的问题啊,有兴趣可以试试,我用交叉编译器和x86 gcc编译都是这样。。。
#define _XOPEN_SOURCE 500
你加了这行??
回复 6# flw2
我确认加了,你试过吗?
我机子的环境gcc (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5
加了Wall后,没有出现你说的情况。
加了_XOPEN_SOURCE的代码发上来看看。
一般加在程序第一行,至少在#include <unistd.h>前面。
或者,gcc后面用_D加。
谢谢楼上各位,我发现这个宏定义必须加在所以#include的前面才行,第一次碰到这种问题。