C standard library
The C standard library ( english C standard library , also known as libc ) is the standard library of the programming language C .
In every standard-compliant operating system-based implementation (hosted environment) of C, the C standard library must be present in its entirety. On the other hand, freestanding environments , such as those frequently encountered in the embedded sector, only have to offer a defined subset of the standard library in order to conform to the standards.
construction
Function prototypes , macros , type declarations and other information are stored in so-called header files , which the programmer integrates into the source code of his program with the help of the C preprocessor, in order to inform the compiler how these functions are to be used. The header files are usually separate files, but the C standard does not explicitly require this: the compiler manufacturer only has to ensure that his C environment behaves as if . The actual implementation of the functions is usually outsourced to a program library . The naming and scope of a header file are standardized today, but the organization of the libraries varies depending on the provider. The C standard library is mostly implemented by the compiler manufacturer, but there are also “bare” compilers, such as gcc , that use the library available on the system. The compiler and system standard library together form the hosted environment .
scope
The C standard library contains around 200 frequently used functions for input and output , mathematical operations , processing of character strings , memory management and other areas. Unlike traditional languages (especially Pascal and Fortran ), C has no built-in complex functionalities for e.g. B. Input and output operations. These must therefore be made available by function libraries.
Compared to the libraries of other languages, namely Java , for example , the C standard library is minimalist. It provides only a basic set of mathematical functions, functions for character string manipulation , type conversion, and file and console-based input and output. It does not provide standardized container data types as the C ++ standard library does, nor does it offer support for graphical user interfaces , network functions and other things that are naturally available in other languages today. A big advantage of the small standard library, however, is that the provision of a standard-compliant C implementation is far easier than with other languages and so porting C to a new platform is comparatively easy.
Most of the C standard library has proven to be very forward-looking. However, some parts are now considered to be errors, but were included due to widespread use. The input function, gets()
for example, is the source of many buffer overflows and has therefore been removed from the library of the latest C standard C11.
The ISO-C standard library currently (ISO-C99) comprises 24 header files. Since some header files have only been added to the C standard in more recent revisions, they are not supported by compilers that implement an older language standard .
Emergence
Since C, unlike other traditional languages such as Pascal or Fortran , does not have any built-in complex functionalities e.g. B. for input and output operations, circles of C programmers were formed in the phase before standardization, who exchanged their ideas and implementations for functions that were used over and over again. Over time, this resulted in extensive function libraries that later served as the basis for the standardization of the C language.
C was developed in the early 1970s by Dennis Ritchie at Bell Laboratories to program the Unix operating system and gained increasing popularity in the years that followed. Many universities and organizations developed their own variants of the language for their projects, so that there were soon compatibility problems between the various implementations . In 1983 the American National Standards Institute (ANSI) formed a committee to define a standardized C. In December 1989, work on the ANSI X3.159-1989 Programming Language C ("C89") standard, which also included the C standard library, was completed. A year later, the standard was adopted by ISO as the international standard ISO / IEC 9899: 1990 ("C90"). Further revisions followed, see also: Variants of the C programming language .
Header files
The following header files are defined by the respective versions of the standard:
C89 / C90 | |
---|---|
assert.h |
Assertions |
ctype.h |
Tests for certain types of characters |
errno.h |
System error codes |
float.h |
Information on the value ranges of floating point numbers |
limits.h |
Information on limitations of the system used |
locale.h |
Settings of the locale |
math.h |
mathematical functions |
setjmp.h |
extended jump functions |
signal.h |
Signal handling |
stdarg.h |
Argument handling for variadic functions |
stddef.h |
additional type definitions |
stdio.h |
Input and output |
stdlib.h |
mixed standard functions, etc. a. Memory management |
string.h |
String operations |
time.h |
Date and Time |
New in C95 (also: "NA1") | |
iso646.h |
alternative notations for logical and bitwise operators |
wchar.h |
Support for Unicode characters |
wctype.h |
like ctype.h , for unicode characters
|
New in C99 | |
complex.h |
Complex numbers |
fenv.h |
Settings for calculating with floating point numbers |
inttypes.h |
Conversion and formatting functions for advanced integer types |
stdbool.h |
Support for Boolean variables |
stdint.h |
platform-independent definition of integer types |
tgmath.h |
type-generic macros for mathematical functions |
New in C11 | |
stdalign.h |
Macros for the memory alignment of objects |
stdatomic.h |
Types and macros for atomic operations between threads |
stdnoreturn.h |
Definition of the no-return macro |
threads.h |
Support for threads , mutexes and monitors |
uchar.h |
Support for UTF-16 and UTF-32 encoded Unicode characters |
Freestanding implementations
Free-standing implementations only need to provide at least the following header files:
Header | C89 / C90 | C95 | C99 |
---|---|---|---|
float.h |
Yes | Yes | Yes |
iso646.h |
Yes | Yes | |
limits.h |
Yes | Yes | Yes |
stdarg.h |
Yes | Yes | Yes |
stdbool.h |
Yes | ||
stddef.h |
Yes | Yes | Yes |
stdint.h |
Yes |
Implementations of the C Standard Library
- The glibc is a free ( LGPL ) implementation of the C standard library that is being developed in the GNU project with the gcc compiler. It is therefore particularly widespread in the Unix area .
- The C library implementations of the BSD operating systems FreeBSD , NetBSD and OpenBSD are also freely available (under a BSD license ) . These represent modern further developments of the C library originally provided by the CSRG .
- Programs for Windows often use the implementation ( msvcrt.dll ) provided by the " Microsoft Visual C ++ " runtime environment , which does not have a special name because it is not available separately.
- As alternatives, there are also less extensive implementations available, which are used particularly on embedded systems , e.g. B. eglibc and especially for μClinux developed uClibc or diet libc .
- The klibc is a free ( GPL or BSD license ) minimal implementation of the C standard library of Hans Peter Anvin , mainly during the boot process of the Linux kernel is used.
- The msp430-libc can be used for programming " TI MSP430 " microcontrollers from Texas Instruments .
- Bionic is a free ( BSD license ) implementation from Google for the Android operating system .
- Newlib is an implementation of the C standard library that has been optimized for creating projects in the area of embedded systems .
- musl is an implementation of the C standard library optimized for static linking .
literature
- British Standards Institute (Ed.): The C Standard - Incorporating TC1 - BS ISO / IEC 9899: 1999 . John Wiley & Sons, 2003, ISBN 0-470-84573-2 .
- PJ Plauger : The Standard C Library . Prentice Hall, 1992, ISBN 0-13-131509-9 .
Web links
- Overview of the C standard library. Retrieved September 21, 2010 (C89).
- ISO / IEC 9899: 1999 (C99) with TC1, TC2 and TC3. (PDF; 3.6 MB) Retrieved on September 12, 2010 (English, non-normative working document).
- Rationale for C99, revision 5.10. (PDF; 877 kB) Accessed September 12, 2010 (English).
- C Library. Retrieved November 26, 2012 .
Individual evidence
- ↑ Rationale for International Standard - Programming Languages - C. (PDF; 877 kB) Accessed September 12, 2010 (English).