[英]definition of off_t with c99
I'm trying to port some code from windows to linux, but I'm having difficulty with support for large files. 我正在尝试将一些代码从Windows移植到Linux,但是在支持大文件方面遇到困难。 off_t seems to be defined when gcc is run with -std=c89 but not for -std=c99.
当gcc与-std = c89一起运行时,似乎已定义off_t,但对于-std = c99却未定义。 Even a trivial test case will not compile:
即使是很小的测试用例也不会编译:
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64
#include <stdio.h>
int main()
{
off_t x = 0;
return 0;
}
It really doesn't seem like this should be difficult (in fact, it's not on all other operating systems). 看来这似乎并不难(实际上,并非在所有其他操作系统上)。 Anyone have any idea what is happening?
有人知道发生了什么吗?
The type off_t
is not defined by ISO C; ISO C未定义
off_t
; it's defined by POSIX. 它是由POSIX定义的。
I get 我懂了
error: unknown type name ‘off_t’
if I compile with either -std=c90
, -std=c99
, or -std=c11
. 如果我使用
-std=c90
, -std=c99
或-std=c11
编译。 That's to be expected, since those options specify conformance to the relevant C standard. 这是可以预期的,因为这些选项指定了与相关C标准的一致性。 Since you're compiling C code that doesn't conform to any of those C standards, you shouldn't use those options.
由于您正在编译不符合任何这些C标准的C代码,因此不应使用这些选项。
I find that off_t
is defined if I compile with -std=gnu90
, -std=gnu99
, or -std=gnu11
. 我发现如果我使用
-std=gnu90
, -std=gnu99
或-std=gnu11
编译, off_t
定义了off_t
。
Also, off_t
is the return type of the lseek
function, whose man page on my system says it requires: 另外,
off_t
是lseek
函数的返回类型,在我的系统上其手册页上说它需要:
#include <sys/types.h>
#include <unistd.h>
You should add those. 您应该添加这些。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.