I study C and I noticed that I can't find the implementation file for some header files like, for example, stdio.h
which is a library which contains a lot of input/output functions, like printf
. Where can I find its implementation?

- 63,369
- 21
- 118
- 128

- 361
- 1
- 5
- 8
-
1Usually you cannot have a look at implementations, that are part of the standard C-code (and all standard headers are part of the standard C-code). – AudioDroid Mar 08 '11 at 14:23
-
@AudioDroid Why is that? Does ANSI have a copyright of the implementation? Or is it just that the source code implementation has never been distributed? Someone somewhere MUST have the source right? – Minh Tran Dec 26 '16 at 01:27
-
1@Minh Tran As you can read below, I am actually not right about this. There is open-source implementations that you can look at. But otherwise, e.g. using the MS C-compiler, yes, they have the rights to their own implementation. The standard just defines how it needs to work, not how to implement it. – AudioDroid Jan 04 '17 at 13:47
5 Answers
Download one of these:
Or, even better, download several of these and compare their implementations. Of course, these are likely doing a lot of things different compared to your particular standard library implementation, but would still be quite interesting for e.g. non-platform-specific functionality such as sprintf.

- 88,732
- 13
- 198
- 189
You need to find the source code for a C standard library like glibc: http://www.gnu.org/s/libc/
You can download the source here: http://ftp.gnu.org/gnu/glibc/ It contains source for all the library functions.

- 1,200
- 7
- 13
On Ubuntu or other OS that uses aptitude for package management, you can use:
apt-get source libc6
for example.
Also, running gcc in verbose mode will tell you the details of the paths it is using. This should help you find which include and library paths it's using.
gcc -v
or
gcc -Wl,--verbose

- 738
- 1
- 8
- 14
If you install the Windows SDK, there is an option to include the standard library source code, so you can also see how it is implemented on Windows.

- 2,362
- 21
- 32