What is FILE in C?


#include <stdio.h>
FILE * fopen(const char *restrict filename, const char *restrict mode);

fopen gives us a FILE, but what is a FILE?

First, FILE used to be a macro, which is why it’s capitalized.

Nowadays, it’s a typedef, defined in stdio.h. On macOS, in /usr/include/stdio.h:

typedef struct __sFILE {
        short   _file;          /* fileno, if Unix descriptor, else -1 */
        // ... more stuff ...

The rest of the definition has some buffers for doing getc, ungetc, etc.

More by Jim

Tagged . All content copyright James Fisher 2016. This post is not associated with my employer. Found an error? Edit this page.