Why is the name of a FILE
structure from stdio.h
written in uppercase?
The most likely reason was that it was once a #define
, and #define
s are conventionally all caps.
To summarize what's already been pointed out:
UPPER CASE is the convention for C "macros".
"FILE" is intended to be an "opaque" structure: you're supposed to use it, but you're not supposed to "known" about it's internals. Which can (and will) change from platform to platform.
Specifically:
http://tigcc.ticalc.org/doc/stdio.html
FILE is the main file control structure for streams. The exact structure of it is very platform-dependent, so ANSI C proposes that the exact structure of this structured type should not be known, and well-written programs do not need to access the internal fields of this structure.
As alk pointed out above, not only CAN "FILE" be implemented as a macro, but in Unix7 it actually WAS implemented as a macro:
http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/include/stdio.h
V7/usr/include/stdio.h =>
#define BUFSIZ 512
#define _NFILE 20
# ifndef FILE
extern struct _iobuf {
char *_ptr;
int _cnt;
char *_base;
char _flag;
char _file;
} _iob[_NFILE];
# endif
...
#define FILE struct _iobuf
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With