What do FILE struct members mean exactly in C?

前端 未结 2 1479
忘掉有多难
忘掉有多难 2020-12-20 03:15
typedef struct _iobuf{
    char*   _ptr;
    int     _cnt;
    char*   _base;
    int     _flag;
    int     _file;
    int     _charbuf;
    int     _bufsiz;
    ch         


        
相关标签:
2条回答
  • 2020-12-20 03:41

    Look at the source code for your system's run-time libraries that implement the FILE-based IO calls if you want to know what those fields mean.

    If you write code that depends on using those fields, it will be non-portable at best, utterly wrong at worst, and definitely easy to break. For example, on Solaris there are at least three different implementations of the FILE structure in just the normal libc runtime libraries, and one of those implementations (the 64-bit one) is opaque and you can't access any of the fields. Simply changing compiler flags changes which FILE structure your code uses.

    And that's just one one version of a single OS.

    0 讨论(0)
  • 2020-12-20 03:46

    _iobuf::_file can be used to get the internal file number, useful for functions that require the file no. Ex: _fstat().

    0 讨论(0)
提交回复
热议问题