BiGYaN wrote:
> I am not an expert in C, but from all the C code I've seen in my last
> 4yrs of coding in C, I observe that programmers only use only "FILE *"
> type and never the actual "FILE" type. So my question is :
>
> <1> what is the actual use of this structure; i.e. can it be used
> anywhere in general programming? It is of course a very important
> structure, but can we make use of it a standard C program? I am told
> that using internals of this structure is not encouraged.
That is correct. The internals of this structure are the sole concern of
the stdio library. You should never modify them. It is occasionally
useful to examine the internals for debugging purposes, but only if
you're pretty familiar with what they mean, which is highly
implementation-specific.
> <2> instead of having,
> typedef struct _iobuf
> {
> char* _ptr;
> int _cnt;
> char* _base;
> int _flag;
> int _file;
> int _charbuf;
> int _bufsiz;
> char* _tmpfname;
> } FILE;
> the stdio.h could have contained a type "pointer to FILE". This would
> save us writing the * every time.
That's certainly true, but experience has shown that typedefs for
pointer types often lead to confusion. They are pointers, and behave
like pointers, but don't obviously look like pointers.
|