Where to find stdio.h functions implementations?

前端 未结 5 2121
-上瘾入骨i
-上瘾入骨i 2020-11-28 05:36

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 i

相关标签:
5条回答
  • 2020-11-28 05:46

    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
    
    0 讨论(0)
  • 2020-11-28 05:51

    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.

    0 讨论(0)
  • 2020-11-28 05:53

    Download one of these:

    • glibc
    • uclibc
    • dietlibc
    • BSD libc

    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.

    0 讨论(0)
  • 2020-11-28 05:57

    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.

    0 讨论(0)
  • 2020-11-28 06:06

    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.

    0 讨论(0)
提交回复
热议问题