Reputation: 381
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?
Upvotes: 29
Views: 23879
Reputation: 91270
Download one of these:
Or, even better, download several of these and compare their implementations. Of course, these are likely doing many things differently compared to your particular standard library implementation, but it would still be quite interesting for e.g. non-platform-specific functionality such as sprintf
.
Upvotes: 37
Reputation: 812
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
Upvotes: 6
Reputation: 2372
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.
Upvotes: 4
Reputation: 1210
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.
Upvotes: 9