Search code examples
cimplementationstandard-library

How do I view implementation source of printf?


I want to see how printf (and many other functions) works.

I wrote

#include <Windows.h>
#include <stdio.h>
int main()
{
printf("");
return 0;
}

in main.c code and go to definition in the right click menu

but it shows something like

_Check_return_opt_ _CRTIMP int __cdecl printf(_In_z_ _Printf_format_string_ const char * _Format, ...);
#if __STDC_WANT_SECURE_LIB__
_Check_return_opt_ _CRTIMP int __cdecl printf_s(_In_z_ _Printf_format_string_ const char * _Format, ...);
#endif

I can't find any hints on how printf works.

Anyone could let me know how to learn standard library implementation?


Solution

  • Here you go:

    http://sourceware.org/git/?p=glibc.git;a=blob;f=stdio-common/vfprintf.c;h=d5690342536bc8cf948c786f663bb63f73f91f3a;hb=HEAD.

    This is from the GNU C library implementation (GLIBC).