错误:“FILE”没有名为“__fileL”的成员
我有一个程序版本,用于编译为 *.o 文件,但现在没有,并给出编译器错误。我曾尝试在 Linux 上使用 gcc 编译器编译我的代码,但编译失败。
我看到编译器错误:
dspter.c:209:18: error: ‘FILE’ has no member named ‘__fileL’
lseek ((int)Ofd->__fileL, 1-sizeof(PDAY_REC99), SEEK_END);
dspter.c:220:13: error: ‘FILE’ has no member named ‘__fileL’
lseek (Ofd->__fileL, 1-sizeof(PDAY_REC99), SEEK_END);
Read99rec ()
{
char bf[20];
if (curnt.ltype == LOAD_PDAY)
{
lseek ((int)Ofd->__fileL, 1-sizeof(PDAY_REC99), SEEK_END);
fgets (Irec, sizeof(Irec), Ofd);
memset (bf, NULL, sizeof (bf));
memcpy (bf, Irec+2, 4);
count01 += atoi(bf);
memset (bf, NULL, sizeof (bf));
memcpy (bf, Irec+6, 6);
recs += atoi(bf);
memset (bf, NULL, sizeof (bf));
memcpy (bf, Irec+12, 16);
ctrl_tot1 += atof(bf);
lseek (Ofd->__fileL, 1-sizeof(PDAY_REC99), SEEK_END);
}
回答
该FILE结构旨在是一种不透明的类型。您不应该访问其成员。
您应该改为使用该fileno函数,该函数将为您提供与FILE对象关联的底层文件描述符。
但是,在这种情况下,您也不想这样做。而不是 using lseek, use fseekwhich 执行相同的操作,但接受一个FILE *而不是文件描述符编号。
- Also, calling `lseek` on the `fileno` of a FILE object can put the FILE out of sync with the kernel-level open file description; those should be `fseek` calls instead.