开发者

Standard library `FILE` type [duplicate]

This question already has answers here: 开发者_如何学JAVA Closed 11 years ago.

Possible Duplicate:

Why is FILE all-caps as in FILE*?

Why is the standard library FILE type written uppercase ?

Is it because of its opaque nature ?

Thank you.


If you look at the naming convention used in C, upper case is typically used for preprocessor macros. My guess is that it originally was implemented as a macro expanding to the concrete type used by the library implementation.


From here

"Strictly speaking, in C the FILE type is a library defined (in stdio.h header) type alias (see typedef keyword). No need to use FILE type as such, only FILE* (pointer to FILE) type. It's (one of;) C language funny idioms. As usually, FILE type alias denotes library defined structure, but don't use its members directly (it's implementation dependent entity)."

Also this:

typedef FILE *stream;

Finally here:


It's not an opaque type, it's usually a C struct, but its fields are implementation defined.

I guess the uppercase is because history...


Not sure, but note that there are only a few types declared in the standard C library. Probably the FILE was the very first defined, and the *_t style wasn't yet invented.

Or maybe in primitive C versions it was a macro... think what happened before they invented the typedef:

#define FILE struct __file

Instead of:

typedef struct __file FILE;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜