What is FILE in C?

Consider:

#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 ...
} FILE;

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


I wrote this because I felt like it. This post is my own, and not associated with my employer.

Jim. Public speaking. Friends. Vidrio.