where is stdin defined in c standard library?
I found this line in stdio.h : extern struct _IO_FILE *stdin; Based on this 'extern' keyword, i assume this is just a declaration. I wonder where is stdin defined and initialized? It's defined in the source code of your C library. You typically only need the headers for compilation, but you can find the source code for many open-source standard libraries (like glibc). In glibc, it's defined in libio/stdio.c as like this: _IO_FILE *stdin = (FILE *) &_IO_2_1_stdin_; Which is in turn defined using a macro in libio/stdfiles.c like this: DEF_STDFILE(_IO_2_1_stdin_, 0, 0, _IO_NO_WRITES); The