C standard library
The C standard library, sometimes referred to as libc, is the standard library for the C programming language, as specified in the ISO C standard. Starting from the original ANSI C standard, it was developed at the same time as the C POSIX library, which is a superset of it. Since ANSI C was adopted by the International Organization for Standardization, the C standard library is also called the ISO C library.
The C standard library provides macros, type definitions and functions for tasks such as string manipulation, mathematical computation, input/output processing, memory management, and input/output.
Application programming interface (API)
Header files
The application programming interface of the C standard library is declared in a number of header files. Each header file contains one or more function declarations, data type definitions, and macros.After a long period of stability, three new header files were added with Normative Addendum 1, an addition to the C Standard ratified in 1995. Six more header files were added with C99, a revision to the C Standard published in 1999, five more files with C11 in 2011 and one more file with C23 in 2023. In total, there are now 30 header files:
| Name | From | Description |
| Declares the assert macro, used to assist with detecting logical errors and other types of bugs while debugging a program. | |
| C99 | Defines a set of functions for manipulating complex numbers. |
| Defines set of functions used to classify characters by their types or to convert between upper and lower case in a way that is independent of the used character set. | |
| For testing error codes reported by library functions. | |
| C99 | Defines a set of functions for controlling floating-point environment. |
| Defines macro constants specifying the implementation-specific properties of the floating-point library. | |
| C99 | Defines exact-width integer types. |
| NA1 | Defines several macros that implement alternative ways to express several standard tokens. For programming in ISO 646 variant character sets. |
| Defines macro constants specifying the implementation-specific properties of the integer types. | |
| Defines localization functions. | |
| Defines common mathematical functions. | |
| Declares the macros setjmp and longjmp, which are used for non-local exits. | |
| Defines signal-handling functions. | |
| C11 | For querying and specifying the alignment of objects. |
| For accessing a varying number of arguments passed to functions. | |
| C11 | For atomic operations on data shared between threads. |
| C23 | For byte ordering and bit representation. |
| C99 | Defines a Boolean data type. This is a placeholder in C23 due to bool becoming a core language feature. |
| C2Y | For obtaining the length of an array using countof. |
| Defines several useful types and macros. | |
| C99 | Defines exact-width integer types. |
| Defines core input and output functions | |
| Defines numeric conversion functions, pseudo-random numbers generation functions, memory allocation, process control functions | |
| C11 | For specifying non-returning functions |
| Defines string-handling functions | |
| C99 | Defines type-generic mathematical functions. |
| C11 | Defines functions for managing multiple threads, mutexes and condition variables |
<time.h> | Defines date- and time-handling functions | |
| C11 | Types and functions for manipulating Unicode characters |
| NA1 | Defines wide-string-handling functions |
| NA1 | Defines set of functions used to classify wide characters by their types or to convert between upper and lower case |
Three of the header files are conditional features that implementations are not required to support.
The POSIX standard added several nonstandard C headers for Unix-specific functionality. Many have found their way to other architectures. Examples include
and . A number of other groups are using other nonstandard headers – the GNU C Library has , and OpenVMS has the va_count function.Documentation
On Unix-like systems, the authoritative documentation of the API is provided in the form of man pages. On most systems, man pages on standard library functions are in section 3; section 7 may contain some more generic pages on underlying concepts.Implementations
systems typically have a C library in shared library form, but the header files may be absent from an installation so C development may not be possible. The C library is considered part of the operating system on Unix-like systems; in addition to functions specified by the C standard, it includes other functions that are part of the operating system API, such as functions specified in the POSIX standard. The C library functions, including the ISO C standard ones, are widely used by programs, and are regarded as if they were not only an implementation of something in the C language, but also de facto part of the operating system interface. Unix-like operating systems generally cannot function if the C library is erased. This is true for applications which are dynamically as opposed to statically linked. Further, the kernel itself operates independently of any libraries.On Microsoft Windows, the core system dynamic libraries provide an implementation of the C standard library for the Microsoft Visual C++ compiler v6.0; the C standard library for newer versions of the Microsoft Visual C++ compiler is provided by each compiler individually, as well as redistributable packages. Compiled applications written in C are either statically linked with a C library, or linked to a dynamic version of the library that is shipped with these applications, rather than relied upon to be present on the targeted systems. Functions in a compiler's C library are not regarded as interfaces to Microsoft Windows.
Many C library implementations exist, provided with both various operating systems and C compilers. Some of the popular implementations are the following:
- The BSD libc, various implementations distributed with BSD-derived operating systems
- GNU C Library, used in GNU Hurd, GNU/kFreeBSD, and most Linux distributions
- Microsoft C run-time library, part of Microsoft Visual C++. There are two versions of the library: the formerly-redistributable MSVCRT which is not compliant to the C99 standard, and the newer UCRT shipped as part of Windows 10 and 11 which is C99-compliant .
- dietlibc, an alternative small implementation of the C standard library
- μClibc, a C standard library for embedded μClinux systems
- * uclibc-ng, an embedded C library, fork of μClibc, still maintained, with memory management unit support
- Newlib, a C standard library for embedded systems and used in the Cygwin GNU distribution for Windows
- klibc, primarily for booting Linux systems
- musl, another lightweight C standard library implementation for Linux systems
- Bionic, originally developed by Google for the Android embedded system operating system, derived from BSD libc
- , developed by Keith Packard, targeting small embedded systems with limited RAM, based on code from Newlib and
Compiler built-in functions
However, the built-in functions must behave like ordinary functions in accordance with ISO C. The main implication is that the program must be able to create a pointer to these functions by taking their address, and invoke the function by means of that pointer. If two pointers to the same function are derived in two different translation units in the program, these two pointers must compare equal; that is, the address comes by resolving the name of the function, which has external linkage.
Linking, libm
Under FreeBSD and glibc, some functions such assin are not linked in by default and are instead bundled in the mathematical library libm. If any of them are used, the linker must be given the directive -lm. POSIX requires that the c99 compiler supports -lm, and that the functions declared in the headers , , and are available for linking if -lm is specified, but does not specify if the functions are linked by default. musl satisfies this requirement by putting everything into a single libc library and providing an empty libm.