what is libc? what are the functions it includes? how can we get the source code of it?

7.9k views Asked by At

As per Wikipedia there are many variants of standard C library based on operating system and compilers. Ref: http://en.wikipedia.org/wiki/C_standard_library

  1. But I want to understand that how plenty of functions which are declared in different headers(eg: stdio.h, string.h, stdlib.h etc. ) are defined in single library. Is the source code file is same for all these header files or there are different libraries for stdio.h, string.h etc? As I am beginner to programming I don't know if multiple source code files can generate a single library like executable. If it is possible then I can understand that libc contains definition of all the standard header files. Where can I see the source code of standard C library?

  2. Is it a static library or dynamic library? If both versions are present in my environment(OS/IDE) which one get linked when I include any standard header file in my source code. Is it IDE dependent? But in case of gcc, programmer does not include libc explicitly.

  3. Is libc a standard name for standard C library?

  4. In windows operating system/environment is it already present or not? If it is present what is the name of it(is it libc only)?

  5. Is there any other standard C library like libm?

1

There are 1 answers

4
DevSolar On BEST ANSWER
  1. Generally speaking, a header (.h) file contains the declarations of functions and variables. Implementation files (.c) contain the actual implementation of the declared functions. Since several implementation files can be translated and linked into a single library binary, you can have one library with multiple headers. Many C library implementations are Open Source, and you can look at their source code at their relative project pages. GNU libc and RedHat newlib are the most prominent. I am sure people will add more in comments.

  2. Implementation defined. You can translate the very same sources into either a static or a dynamic library. It is not uncommon to have both versions installed on your system. Since virtually every executable requires libc, it is usually added to the linker input by default so you don't have to add -lc to every command line.

  3. No. The standard name for the standard C library is "The Standard C Library". Note that virtually all implementations of the standard library extend the library with non-standard functions. These remain non-standard, even if they come as part of the standard library. (alloca() springs to mind.)

  4. MSVCRT.dll or somesuch, if I remember correctly.

  5. libm stands for the math section of the standard library, which is not added to the linker input by default as it is seldom required. There is only one standard C library, the one described by the ISO/IEC 9899 language standard (hence the name). There are many other libraries that can readily be assumed to be present on a given system, but only what's described in the ISO/IEC documents is "the standard".