8

Possible Duplicate:
Where to find stdio.h functions implementations ?

Hi, I am trying to find the function definitions of the functions defined in stdio.h header file, I want to learn how functions like printf() is achieved, but I can't find any preprocessor directives link in stdio.h to the implementation file elsewhere. How can a C Compiler know where to find the implementations when there are no direct references to the function definition file? (I learned that .h file may accompany with a same name .c implementation file from an objective-c book.) Could you help me? Thanks! I am using GCC on Mac OS X.

Community
  • 1
  • 1
Oliver
  • 543
  • 3
  • 6
  • 9
  • 2
    A "header" need not be a file at all. A compiler can actually have it all built in. – Wiz Jun 04 '11 at 01:40
  • Since you haven't specified which compiler you're using, you can see Microsoft's implementation if you have a non-express version of Visual Studio AFAIK. They are typically found in: `\Program Files\Microsoft Visual Studio [ver no.]\VC\crt` – Jeff Mercado Jun 04 '11 at 01:43

2 Answers2

7

FreeBSD's libc is pretty well laid out in its src repository.

http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/

e.g. for printf(3):

http://svnweb.freebsd.org/base/head/lib/libc/stdio/printf.c?view=markup

http://svnweb.freebsd.org/base/head/lib/libc/stdio/vfprintf.c?view=markup

Dan Bechard
  • 5,104
  • 3
  • 34
  • 51
Sean
  • 9,888
  • 4
  • 40
  • 43
  • 2
    +1 for FreeBSD's refreshingly sane source tree – jwd Jun 04 '11 at 01:45
  • 1
    You might want to link to `vfprintf()` as well since thats the function that does all the heavy lifting - parsing the actual arguments. – Wiz Jun 04 '11 at 01:49
3

Try downloading source code for GLIBC library project. That's where definitions for standard functions are when using GCC compiler (and derivates).

Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
  • 1
    `gcc` doesn't have to use `glibc`. But if you're running a typical Linux distro then you'll most likely be using it. – asveikau Jun 04 '11 at 01:37