0

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?

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
kim taeyun
  • 1,837
  • 2
  • 24
  • 49
  • 2
    `printf` is easily one of the most complicated functions imaginable. Just try and work out in your head how *you* would format a floating point number in the usual decimal notation. (That said, all the other, non-floating point parts of `printf` are straight-forward.) – Kerrek SB Jun 09 '12 at 11:28
  • There is an open source implementation of libc. You can download it and inspect it. (which is not true for the unneeded non-standard header `` ) – wildplasser Jun 09 '12 at 11:34

1 Answers1

2

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).

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
  • 1
    This is misleading as OP is working on Windows and may use the MSVC `printf()` which is considerably different. – fuz Feb 08 '16 at 10:44
  • @fuzxxl: true. But it seemed like the OP was interested in general implementation concepts, so the GNU version should be sufficient for that. – Oliver Charlesworth Feb 08 '16 at 11:31
  • 1
    I disagree. The glibc version of printf is probably one of the most convoluted and complex implementations (just as all of the glibc is). Other libc implementations contain much simpler code for printf. – fuz Feb 08 '16 at 12:28