C standard library
The C standard library or libc is the standard library for the C programming language, as specified in the ISO C standard.[1] Starting from the original ANSI C standard, it was developed at the same time as the C library POSIX specification, which is a superset of it.[2][3] Since ANSI C was adopted by the International Organization for Standardization,[4] 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 handling, mathematical computations, input/output processing, memory management, and several other operating system services.
Application programming interface (API)[edit]
Header files[edit]
The application programming interface (API) 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 (iso646.h
, wchar.h
, and wctype.h
) were added with Normative Addendum 1 (NA1), an addition to the C Standard ratified in 1995. Six more header files (complex.h
, fenv.h
, inttypes.h
, stdbool.h
, stdint.h
, and tgmath.h
) were added with C99, a revision to the C Standard published in 1999, and five more files (stdalign.h
, stdatomic.h
, stdnoreturn.h
, threads.h
, and uchar.h
) with C11 in 2011. In total, there are now 29 header files:
Problems and workarounds[edit]
Buffer overflow vulnerabilities[edit]
Some functions in the C standard library have been notorious for having buffer overflow vulnerabilities and generally encouraging buggy programming ever since their adoption.[a] The most criticized items are:
The C standard library in other languages[edit]
Some languages include the functionality of the standard C library in their own libraries. The library may be adapted to better suit the language's structure, but the operational semantics are kept similar. The C++ language, for example, includes the functionality of the C standard library in the namespace std
(e.g., std::printf
, std::atoi
, std::feof
), in header files with similar names to the C ones (cstdio
, cmath
, cstdlib
, etc.). Other languages that take similar approaches are D, Perl, Ruby and the main implementation of Python known as CPython. In Python 2, for example, the built-in file objects are defined as "implemented using C's stdio
package",[38] so that the available operations (open, read, write, etc.) are expected to have the same behavior as the corresponding C functions. Rust has a crate called libc which allows several C functions, structs, and other type definitions to be used.[39]
Comparison to standard libraries of other languages[edit]
The C standard library is small compared to the standard libraries of some other languages. The C library provides a basic set of mathematical functions, string manipulation, type conversions, and file and console-based I/O. It does not include a standard set of "container types" like the C++ Standard Template Library, let alone the complete graphical user interface (GUI) toolkits, networking tools, and profusion of other functionality that Java and the .NET Framework provide as standard. The main advantage of the small standard library is that providing a working ISO C environment is much easier than it is with other languages, and consequently porting C to a new platform is comparatively easy.