Joona I Palaste said:
Why is the standard C type for file handles FILE* instead of FILE?
AFAIK the type FILE is a pre-defined typedef for some other type anyway.
So why not make it instead a typedef for a *pointer* to that type? For
one thing, that would stop people trying to poke around at the insides
of a FILE. For another, it could allow for cases where the "real" type
behind FILE is not a pointer to anything.
IMHO Making FILE a typedef alias for pointer-to-realfiletype would've
caused even more confusion among programmers, and on itself wouldn't
have kept anybody from manipulating the internals of the underlying
type (lookup the struct declaration in stdio.h as before, and use .
instead of ->, that's all).
Actually, the IMNSHO most reasonable solution would've been to keep
the typedef as is, but hide the internals of the underlying type by
moving its declaration from the header to the library source (make
it an opaque type), e.g. something like:
/************* stdio.h *************/
typedef
struct _iobuf
FILE;
FILE *fopen(const char *, const char *);
/* .... */
/***********************************/
/************* stdio.c *************/
#include <stdio.h>
struct _iobuf
{
int _file;
int _flag;
/* etc. */
};
FILE *fopen(const char *filename, const char *mode)
{
/* yaddayaddayadda */;
}
/* .... */
/***********************************/
This approach however has the drawback that getc and putc could
not have been easily implemented as simple macros, but given the
potential dangers that arise from such macro implementations,
it's highly debatable if this would've been a big loss (IMO not).
Regards