C standard library

from Wikipedia, the free encyclopedia

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

literature

Web links

Individual evidence

  1. Rationale for International Standard - Programming Languages ​​- C. (PDF; 877 kB) Accessed September 12, 2010 (English).