2
typedef struct _iobuf{
    char*   _ptr;
    int     _cnt;
    char*   _base;
    int     _flag;
    int     _file;
    int     _charbuf;
    int     _bufsiz;
    char*    _tmpfname;
   }  FILE;

I try to print them but I don't understand what they mean. Here What exactly is the FILE keyword in C? He said "Some believe that nobody in their right mind should make use of the internals of this structure." but he didn't explain what they mean.

Community
  • 1
  • 1
cengizhan
  • 85
  • 2
  • 6
  • possible duplicate of [What exactly is the FILE keyword in C?](http://stackoverflow.com/questions/5672746/what-exactly-is-the-file-keyword-in-c) – Solal Pirelli Apr 21 '15 at 09:48
  • No , becuase he didn't explain members of the _iobuf. – cengizhan Apr 21 '15 at 09:54
  • 3
    You shouldn't care about the content of the FILE structure. This structure is entirely implementation dependent. If you really want to know what all of these members mean, you should study the source code of the your library you use. BTW [here](http://en.allexperts.com/q/C-1587/2008/5/FILE-Structure.htm) is an explanation, but you will see that the FILE structure there is different from your FILE structure. But anyways you should never mess around with the internals of the FILE structure in a real program. – Jabberwocky Apr 21 '15 at 10:05

2 Answers2

5

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.

Andrew Henle
  • 32,625
  • 3
  • 24
  • 56
0

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

Pierre
  • 4,114
  • 2
  • 34
  • 39
  • 4
    The proper and portable way to obtain the underlying integer file descriptor for a `FILE` structure is to use the [`fileno()` function](https://pubs.opengroup.org/onlinepubs/9699919799/functions/fileno.html) in code like `int fd = fileno( fp );`, where `fp` is a `FILE *` value referring to an open file. – Andrew Henle Mar 25 '21 at 20:55