linux FILE 类型.

  stdio.h 头文件中,有以下内容(用内部行号解释):

 1 /* The opaque type of streams.  This is the definition used elsewhere.  */
 2  46 typedef struct _IO_FILE FILE;
 3 ...
 4 #include <libio.h>
 5 ...
 6 /* Standard streams.  */
 7 142 extern struct _IO_FILE *stdin;          /* Standard input stream.  */
 8 143 extern struct _IO_FILE *stdout;         /* Standard output stream.  */
 9 144 extern struct _IO_FILE *stderr;         /* Standard error output stream.  */145 #ifdef __STDC__
10 146 /* C89/C99 say they‘re macros.  Make them happy.  */
11 147 #define stdin stdin
12 148 #define stdout stdout
13 149 #define stderr stderr
14 150 #endif

  由上,知道 FILE 是 struct _IO_FILE 类型的别名,或者说 FILE 类型就是 struct _IO_FILE 类型,由 第143行中的 _IO_FILE,往上追溯至 include 预处理指令,我们可以在 libio.h 头文件中看到 _IO_FILE 结构体的定义:

 1 struct _IO_FILE {
 2 269   int _flags;           /* High-order word is _IO_MAGIC; rest is flags. */
 3 270 #define _IO_file_flags _flags
 4 271
 5 272   /* The following pointers correspond to the C++ streambuf protocol. */
 6 273   /* Note:  Tk uses the _IO_read_ptr and _IO_read_end fields directly. */
 7 274   char* _IO_read_ptr;   /* Current read pointer */
 8 275   char* _IO_read_end;   /* End of get area. */
 9 276   char* _IO_read_base;  /* Start of putback+get area. */
10 277   char* _IO_write_base; /* Start of put area. */
11 278   char* _IO_write_ptr;  /* Current put pointer. */
12 279   char* _IO_write_end;  /* End of put area. */
13 280   char* _IO_buf_base;   /* Start of reserve area. */
14 281   char* _IO_buf_end;    /* End of reserve area. */
15 282   /* The following fields are used to support backing up and undo. */
16 283   char *_IO_save_base; /* Pointer to start of non-current get area. */
17 284   char *_IO_backup_base;  /* Pointer to first valid character of backup area     */
18 285   char *_IO_save_end; /* Pointer to end of non-current get area. */
19 286
20 287   struct _IO_marker *_markers;
21 288
22 289   struct _IO_FILE *_chain;
23 
24 291   int _fileno;
25 292 #if 0
26 293   int _blksize;
27 294 #else
28 295   int _flags2;
29 296 #endif
30 297   _IO_off_t _old_offset; /* This used to be _offset but it‘s too small.  */
31 298
32 299 #define __HAVE_COLUMN /* temporary */
33 300   /* 1+column number of pbase(); 0 is unknown. */
34 301   unsigned short _cur_column;
35 302   signed char _vtable_offset;
36 303   char _shortbuf[1];
37 304
38 305   /*  char* _save_gptr;  char* _save_egptr; */
39 306
40 307   _IO_lock_t *_lock;
41 308 #ifdef _IO_USE_OLD_IO_FILE
42 309 };

  稍微注意的是(外侧行号解释), stdio.h 头文件中的第 4行优先于第 2 行执行,虽然第2行在第4行的前面. 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。