在ubuntu-18.10中的apue.3e中使用$ make时,如何修复“结构'FILE'没有名为'__pad'的成员”错误

时间:2019-04-20 06:06:08

标签: ubuntu unix

我是学习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]
 }

1 个答案:

答案 0 :(得分:0)

我认为我解决了这个问题。

作者说:“以下内容不可移植。”

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

我在/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