C FILE pointer, why not just use the FILE type directly?
A FILE
- resource. This file exists only once and cannot be moved. This makes FILE
C meaningless semantically. Whenever you have a resource, you refer to the resource by passing a pointer to the resource, which is what the C API does.
(Moreover, the definition FILE
is private to the implementation, not the part of the standard that is an essential part of the freedom you want to implement.)
source to share
C originally did not have the ability to pass structures by value, this was added in ANSI C89.
FILE
would not work in K&R C. Since it FILE *
works just fine, there was no need or benefit to change the functions to work with FILE
instead of FILE *
when ANSI C was compiled.
As Kerrek SB points out, another benefit FILE *
is that there FILE
can be a struct typedef'd tag, and that leaves the implementation free to implement whichever is better, without breaking any working programs.
source to share