definition of basic functions of C/C++

I was trying to understand the header files like "stdio.h", "math.h", etc... but when I open those files I find only the prototypes of functions like "fget()" or "printf()", then searching on google I found this link :
http://www.cplusplus.com/forum/beginner/75057/#msg402385

here, the guy said that he found this code in a source code (obviously), but my question is : from where is this code? Is it from the compiler, or I can find it without downloading the source code from the compiler?

Thanks for any help...


1
2
3
4
5
6
7
8
9
  __mingw_stdio_redirect__
int printf (const char *__format, ...)
{
  register int __retval;
  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
  __retval = __mingw_vprintf( __format, __local_argv );
  __builtin_va_end( __local_argv );
  return __retval;
}
Gnomo Verde said:
...only the prototypes...

Correction: declarations.

Gnomo Verde said:
where is this code?
You already have it You should have the headers, if that's what you're iterested in. What IDE (https://en.wikipedia.org/wiki/Integrated_Development_Environments) are you using?

If you want full documentation on the language: http://en.cppreference.com/w/
You will find what you're looking for there.

Note: The functions you're interested in are NOT C++, they are C.
Last edited on
I'm using Code::Blocks 13.12...
> can find it without downloading the source code from the compiler?

We can browse the source code repository directly

For instace, FreeBSD 10.1 libc/stdio (via the web interface to svn).

printf: https://svnweb.freebsd.org/base/release/10.1.0/lib/libc/stdio/printf.c?revision=274417&view=markup

which calls vfprintf:
https://svnweb.freebsd.org/base/release/10.1.0/lib/libc/stdio/vfprintf.c?revision=274417&view=markup
Caveat: comment in vfprintf.c
1
2
3
4
5
/*
* Actual printf innards.
*
* This code is large and complicated...
*/


or for C++: std::initialiser_list (contrib/libc++)
https://svnweb.freebsd.org/base/release/10.1.0/contrib/libc%2B%2B/include/initializer_list?revision=274417&view=markup
Last edited on
On Unix machines, the standard libraries for C and C++ are built as part of the base system. For instance, the FreeBSD buildworld builds (from source) libc, the LLVM infractuture, clang++ and libc++ (among others).
http://www.freebsd.org/doc/en/books/handbook/makeworld.html

On 'distro' based implementations, these are typically pre-compiled by the maintainer of the distro, and distributed as parts of pre-built libraries.

When you downloaded Code::Blocks 13.12 along with the MinGW tool-chain, it contains the C and C++ libraries (in binary form) which were pre-built from the source code. Your installation would have <stdio.h> as a header file, but it would not have the source code for printf.c - printf.c was compiled and the resultant binary object file was placed in one or more libraries. When you call printf(), the call is forwarded to the (binary) code from the library which your program would have linked to.
Thank you very much
Topic archived. No new replies allowed.