prista
prista

Reputation: 381

Where to find stdio.h functions implementations?

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

Answers (5)

Erik
Erik

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

plafratt
plafratt

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

bcsanches
bcsanches

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

Ben
Ben

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

schnaader
schnaader

Reputation: 49719

For example here. Google is your friend - just search for stdio.c. But note that you should handle these as "one implementation of many possible" - you don't know how your compiler is doing it by reading those, you just get an idea of how it can be done.

Upvotes: 7

Related Questions