I double-checked all the similar questions here, I really hope not to duplicate. I am intrigued by the the following extract from stdio.h:
typedef struct _iobuf {
/* Members here omitted ... */
} FILE;
extern FILE _iob[20];
We define a new type named FILE by using the struct syntax. Just after that, we declare an extern variable _iob of type FILE. Therefore, this variable must come from another place. But, since the definition of FILE is in this file, how can it be possible? I see two possibilities only. The first is to have something like:
#include <stdio.h>
FILE _iob[20] = /* definition */
The second is to have another source file where the struct is copy-pasted and the variable declared, I guess a very bad practice that we can omit.
Since I am a self-learner, I would be very happy to receive a confirm of my understanding.Thanks!
typedefdefines the layout of the data typeFILE. Theexternsays that the code has one of those at its disposal, but its location is defined elsewhere.typedefcan be repeated elsewhere without issues. Yes, it's true that it's normal to have the definition in one header file only and include that everywhere, but it's not a requirement.