gpt4 book ai didi

ubuntu - 如何修复 "struct ' FILE' has no member named '__pad'"在 ubuntu-18.10 中使用 $make in apue.3e 时出错

转载 作者:行者123 更新时间:2023-12-04 18:31:37 24 4
gpt4 key购买 nike

我是学习APUE的新手。当我在 apue.3e 文件夹中使用 $make 时,有一些错误我不知道如何修复。对了,我用的是ubuntu-18.10。

buf.c:104:13: note: in expansion of macro ‘_flag’
return(fp->_flag & _IOLBF);
^~~~~
buf.c: In function ‘buffer_size’:
buf.c:92:15: error: ‘FILE’ {aka ‘struct _IO_FILE’} has no member named ‘__pad’; did you mean ‘__pad5’?
#define _base __pad[2]
^~~~~
buf.c:111:13: note: in expansion of macro ‘_base’
return(fp->_base - fp->_ptr);
^~~~~
buf.c:91:14: error: ‘FILE’ {aka ‘struct _IO_FILE’} has no member named ‘__pad’; did you mean ‘__pad5’?
#define _ptr __pad[1]
^~~~~
buf.c:111:25: note: in expansion of macro ‘_ptr’
return(fp->_base - fp->_ptr);
^~~~
buf.c: In function ‘is_unbuffered’:
buf.c:99:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
buf.c: In function ‘is_linebuffered’:
buf.c:105:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
buf.c: In function ‘buffer_size’:
buf.c:115:1: warning: control reaches end of non-void function [-Wreturn-type]
}

最佳答案

我想我解决了这个问题。

作者说“以下是不可移植的。”

所以也许你需要修改一些东西。

我在/usr/include/bits/types/struct_FILE.h 中找到了我的 FILE(typedef _IO_FILE)

我的 _IO_FILE 是这样的:

struct _IO_FILE
{
int _flags; /* High-order word is _IO_MAGIC; rest is flags. */

/* The following pointers correspond to the C++ streambuf protocol. */
char *_IO_read_ptr; /* Current read pointer */
char *_IO_read_end; /* End of get area. */
char *_IO_read_base; /* Start of putback+get area. */
char *_IO_write_base; /* Start of put area. */
char *_IO_write_ptr; /* Current put pointer. */
char *_IO_write_end; /* End of put area. */
char *_IO_buf_base; /* Start of reserve area. */
char *_IO_buf_end; /* End of reserve area. */

/* The following fields are used to support backing up and undo. */
char *_IO_save_base; /* Pointer to start of non-current get area. */
char *_IO_backup_base; /* Pointer to first valid character of backup area */
char *_IO_save_end; /* Pointer to end of non-current get area. */

struct _IO_marker *_markers;

struct _IO_FILE *_chain;

int _fileno;
int _flags2;
__off_t _old_offset; /* This used to be _offset but it's too small. */

/* 1+column number of pbase(); 0 is unknown. */
unsigned short _cur_column;
signed char _vtable_offset;
char _shortbuf[1];

_IO_lock_t *_lock;
#ifdef _IO_USE_OLD_IO_FILE
};

然后我修改buf.c:

细节是我将“flag”更改为“flags”和“return(fp->_base - fp->_ptr);”到“返回(fp->_IO_buf_end - fp->_IO_buf_base);”

    #elif defined(_IONBF)

int
is_unbuffered(FILE *fp)
{
return(fp->_flags & _IONBF);
}

int
is_linebuffered(FILE *fp)
{
return(fp->_flags & _IOLBF);
}

int
buffer_size(FILE *fp)
{
#ifdef _LP64
return(fp->_IO_buf_end - fp->_IO_buf_base);
#else
return(BUFSIZ); /* just a guess */
#endif
}

最后我得到了这个结果。

enter any character
a
one line to standard error
stream = stdin, fully buffered, buffer size = 1024
stream = stdout, fully buffered, buffer size = 1024
stream = stderr, unbuffered, buffer size = 1
stream = /etc/passwd, fully buffered, buffer size = 4096

关于ubuntu - 如何修复 "struct ' FILE' has no member named '__pad'"在 ubuntu-18.10 中使用 $make in apue.3e 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55770771/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com