Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the FILE structure from stdio.h written in uppercase?

Tags:

c

Why is the name of a FILE structure from stdio.h written in uppercase?

like image 945
David Avatar asked Nov 03 '15 19:11

David


2 Answers

The most likely reason was that it was once a #define, and #defines are conventionally all caps.

like image 146
Edward Karak Avatar answered Sep 19 '22 22:09

Edward Karak


To summarize what's already been pointed out:

  1. UPPER CASE is the convention for C "macros".

  2. "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.

  1. 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
...
like image 20
paulsm4 Avatar answered Sep 20 '22 22:09

paulsm4