The standard C library (also known as libc , crt ) is the part of the ANSI C standard devoted to header files and library routines . It is a description of the implementation of general operations, such as processing I / O and strings , in the C programming language . The standard C language library is a description of the programming interface , and not a real library suitable for use in the compilation process.
| Standard library C programming language |
|
Content
- 1 Structure
- 1.1 Views on the structure
- 2 History
- 3 ANSI standard
- 3.1 ANSI C library header files with additions C99 and C11
- 4 C standard library in other languages
- 5 General library support
- 6 Built-in compiler functions
- 7 POSIX Standard Library
- 8 Implementations
- 9 See also
- 10 Links
- 11 Additional sources
Structure
The name and characteristics of each function are indicated in a file called a header file , but the current implementation of the functions is described separately in the library file . The name and capabilities of the header files are becoming common, but the organization of libraries is still heterogeneous. The standard library usually comes with the compiler . Since C compilers often provide extended functionality not defined by the ANSI C standard, the standard library of one compiler is not compatible with the standard libraries of other compilers.
Structural Opinions
Most of the standard C language library seems to be well-designed. Some of the individual parts that were advantageous in the past can cause errors. The gets () string input functions (and the use of scanf () to read input strings) are the source of many buffer overflows , so most programming guides recommend avoiding such tricks. The strcpy () function is also very notorious. Another ambiguous function is strtok() , a function designed as the simplest lexical analyzer , but with many pitfalls and therefore very difficult to use.
The choice of using the type size_t instead of int for the number of elements specified for fread () and fwrite () is incompatible with the developed general semantics for size_t (to represent the number of bytes).
stdio quite limited (too high a level to be used in many situations) and the standard does not allow the user to reassign or expand his properties on his own. As a result, for many applications, their own wrapper libraries are developed around lower-level mechanisms and functions implemented by the OS, such as POSIX. For example, stdio does not work with signals or asynchronous non-packet I / O modes, which are widely used in network servers. As a result, only servers using the whole process model for the client can fully rely on stdio functions to serve them on POSIX- compatible systems in batch I / O.
Certain features of the standard library should be avoided when developing multi-threaded applications. The flow control primitives were intended for the rest of the OS and ignore common standards, such as the POSIX thread library, expecting C programmers to take care of this themselves while working with reuse and synchronization. Neither the C language nor its standard library can test such system-specific results in any way.
History
Before standardization, the C programming language did not provide built-in functionality, such as input-output operations (unlike traditional languages such as Kobol and Fortran ). Later, in the community of C programmers, ideas arose that were implemented in what we now call the C Standard Library to support this functionality. Most of these ideas eventually came together to define the standard for the C programming language.
Both Unix and C were created at AT & T's Bell Laboratories in the late 1960s and early 1970s. In the 1970s, the C programming language began to enjoy incredible popularity. Many universities and organizations have begun to create their own language options, more suitable for their own needs. Since the early 1980s, compatibility issues between various C language implementations have become too obvious. In 1983 , the American National Standards Institute (ANSI) formed a committee to adopt the C language standard, known as "ANSI C". This work resulted in the creation of the so-called C89 standard in 1989 . Part of the final standard was a set of libraries called the ANSI C Standard Library .
Subsequent versions of the C standard added some new and most useful header files to the library. Support for these new extensions was implementation dependent.
The header files <iso646.h> , <wchar.h> and <wctype.h> were added in Appendix 1 (abbreviated as NA1 ), an addendum to the C Language Standard, ratified in 1995 .
The header files <complex.h> , <fenv.h> , <inttypes.h> , <stdbool.h> , <stdint.h> and <tgmath.h> were added in C99 , a version of the C Language Standard published in 1999 .
ANSI standard
The ANSI C standard library consists of 24 header files, each of which can be connected to a software project using one directive. Each header file contains declarations of one or more functions, data type definitions, and macros. The contents of these header files are listed below.
Compared to some other languages (like Java ), the standard library is extremely small. The library provides support for the basic set of mathematical functions, string processing, type conversion, file and console I / O. It does not contain a standard set of “container types” as a standard library of C ++ language templates , components for working with a graphical user interface (GUI), a network, and other various functions that Java supports by standard. The main advantage of the small standard library is the simplification of working with the ANSI C environment compared to other languages, and therefore the simplification of porting C programs to new platforms.
Many other libraries have been designed to support the similar functionality provided by other languages in their standard libraries. For example, in the GNOME desktop environment development project , a set of graphical tools GTK + and GLib was developed - a library of container data structures, as well as many other well-known examples. The variety of libraries available means that some top-level tools have proven useful over time. A significant minus is that they often do not interact very well with each other, so programmers are often more familiar with working with different sets of libraries, and their sets can be available on various specific platforms.
ANSI C library header files with additions C99 and C11
| < assert.h > | Contains a claims macro used to detect logical and some other types of errors in the debugged version of the program. |
| < complex.h > | A set of functions for working with complex numbers . (Appeared in C99 ) |
| < ctype.h > | Contains functions used to classify characters by their types or to convert between upper and lower case regardless of the encoding used (usually ASCII or one of its extensions, although there are implementations that use EBCDIC ). |
| < errno.h > | To check for error codes returned by library functions. |
| < fenv.h > | To control an environment using floating point numbers . (Appeared in C99 ) |
| < float.h > | It contains predefined constants describing the specifics of the implementation of the library properties for working with floating-point numbers , such as the minimum difference between two different floating-point numbers (_EPSILON), the maximum number of precision digits (_DIG) and the range of valid numbers (_MIN, _MAX ) |
| < inttypes.h > | For accurate conversion of integer types. (Appeared in C99 ) |
| < iso646.h > | For programming in ISO 646 encoding. (Appeared in NA1 ) |
| < limits.h > | It contains predefined constants that determine the specifics of the implementation of the properties of integer types, such as, for example, the range of valid values (_MIN, _MAX). |
| < locale.h > | For setlocale () and related constants. Used to select the appropriate language . |
| < math.h > | To calculate basic mathematical functions |
| < setjmp.h > | Declares setjmp and longjmp macros used for non-local transitions |
| < signal.h > | To control signal processing |
| < stdarg.h > | To access a different number of arguments passed to functions. |
| < stdbool.h > | For boolean data types. (Appeared in C99 ) |
| < stdint.h > | To define different types of integers. (Appeared in C99 ) |
| < stddef.h > | To define several standard types and macros. |
| < stdio.h > | It implements the main input and output capabilities in the C language. This file contains a very important printf function. |
| < stdlib.h > | To perform many operations, including conversion, pseudo-random number generation , memory allocation, process control, environment, signals, search and sorting. |
| < string.h > | To work with various kinds of strings. |
| < tgmath.h > | For typical math functions. (Appeared in C99 ) |
| < threads.h > | The header file <threads.h> along with <stdatomic.h> provides support for concurrent programming. (Appeared in C11 ) |
| < time.h > | To convert between different time and date formats. |
| < wchar.h > | For processing "wide" streams and several types of strings using "wide" characters (support for a set of languages). (Appeared in NA1 ) |
| < wctype.h > | To classify "wide" characters. (Appeared in NA1 ) |
C standard library in other languages
Some languages provide the functionality of the standard C library with their own libraries. The library can be adapted for language structures, but the semantics of operations remain similar. The C ++ programming language , for example, contains the functionality of the standard ANSI C library in the std namespace (for example, std::printf , std::atoi , std::feof , etc.), in header files with similar names as in C ( cstdio , cmath , cstdlib , etc.) Other languages that use similar approaches include, for example, D and Python . In the latter, for example, the built -in file object is defined as “implemented using the C stdio package” [1] , so that the available operations (opening, reading, writing, etc.) are expected to have the same behavior as the corresponding ones C language functions.
General library support
It is not standardized yet, but C programs may depend on subprogram libraries that contain code used by the compiler at runtime. The code that initializes the process for the operating system, for example, before calling main() , is implemented in the C Run-Time Library (CRT) for this version of the compiler. The CRT library code can help with the implementation of other features of the language, such as handling uncaught exceptions or the implementation of work with floating point numbers.
The standard C library only regulates the presence of the above routines and their behavior. Since the implementation of the compiler may depend on the presence of these additional functions, it all depends on which routines are compiled into the C Standard Library, so any program developed with their help will need them.
Although they are often confused with the Standard C library because of their configuration, the CRT library is not a standardized part of the language and depends on the particular delivery of the software product.
Built-in compiler functions
Some compilers (for example, GCC [1] ) support internal versions of many functions of the C Standard Library; that is, function implementations are written to the compiled object module , and the program calls the internal versions instead of the functions of the common C library. This reduces the overhead of a function call, especially if the function call is replaced by built-in options, and other forms of optimization are allowed (if the compiler supports controlling the characteristics of internal options), but can lead to problems during debugging (for example, internal versions cannot be replaced by instrumental versions for check).
POSIX Standard Library
POSIX (and SUS ) determine the number of routines that can be accessed beyond those defined in the C Standard Library; they often implement similar functionality with the Standard Library with varying degrees of similarity. For example, glibc implements functions such as fork in libc.so, but before calling the library, the libraries are combined into glibc, although this is declared as a separate library with its own linker flag. Often, such POSIX-compliant functionality is considered part of the library; the corresponding C library can thus be identified as an ANSI or ISO C library.
Implementations
There are many implementations that come with various operating systems, as well as with C compilers. On BSD systems, for example, a system library is built into the operating system and is supported by a common source repository. On most systems, the library can be found under the name " libc ".
Although there are so many implementations, here is a short list of the most popular libraries:
- GNU C Library - The Most Common Linux Implementation
- Microsoft C Run-time Library
- dietlibc - an alternative small implementation of the C Standard Library
- uClibc - Standard C language library for Linux- based embedded systems
- Newlib - Standard C language library for embedded systems (MMU-less) [2]
- klibc - used mainly for booting Linux-systems.
- eglibc is a variation of glibc for embedded systems.
- musl is an implementation of the standard C language library for Linux , striving to be compatible primarily with modern standards, and secondly with glibc. [3]
See also
- List of C Standard Library Functions
- C ++ Standard Library
Links
- ↑ Other built-in functions provided by GCC , GCC Guide
- ↑ Re: Does Newlib support mmu-less processors?
- ↑ musl - Introduction . www.musl-libc.org. Date of treatment January 30, 2017.
Additional Sources
- C Standard Language Library : Detailed description of header files
- C Library User Guide
- Microsoft C Language Launch Libraries on MSDN
- NetBSD C Libraries Guide and C Source Libraries : Good Academic Guides.