首页 > 代码库 > linux FILE 类型.
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 stdin12 148 #define stdout stdout13 149 #define stderr stderr14 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 28620 287 struct _IO_marker *_markers;21 28822 289 struct _IO_FILE *_chain;23 24 291 int _fileno;25 292 #if 026 293 int _blksize;27 294 #else28 295 int _flags2;29 296 #endif30 297 _IO_off_t _old_offset; /* This used to be _offset but it‘s too small. */31 29832 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 30438 305 /* char* _save_gptr; char* _save_egptr; */39 30640 307 _IO_lock_t *_lock;41 308 #ifdef _IO_USE_OLD_IO_FILE42 309 };
稍微注意的是(外侧行号解释), stdio.h 头文件中的第 4行优先于第 2 行执行,虽然第2行在第4行的前面.
linux FILE 类型.
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。