All Topics  
C standard library

 

   Email Print
   Bookmark   Link






 

C standard library



 
 
The C standard library consists of a set of sections of the ISO C standard which describe a collection of header file
Header file

In computer programming, particularly in the C and C++ programming languages, a header file or include file is a computer file, usually in the form of source code, that a compiler automatically includes when processing another source file....
s and library
Library (computer science)

In computer science, a library is a collection of subroutines or Class used to develop software. Libraries contain code and data that provide services to independent programs....
 routines used to implement common operations, such as input/output
Input/output

In computing, input/output, or I/O, refers to the communication between an information processing system , and the outside world ? possibly a human, or another information processing system....
 and string handling, in the C programming language
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
. The C standard library is an interface standard described by a document; it is not an actual library of software routines available for linkage to C programs. No such implementation is properly called C standard library.

Note there is the term C library which may either informally be used as a synonym for C standard library (as in "malloc is the name of a function in the C library"); or may refer to to a particular implementation which provides the C standard library features and other features (as in "this compiler comes with a very reliable C library for ISO C and POSIX programming"); or to any library whatsoever which has an interface for linking to C programs (as in "this software company offers a C library of Fast Fourier Transform functions").

The term C run-time library is used on some platforms to refer to a set of base libraries, which may be distributed in dynamically linkable form with an operating system (with or without header files), or distributed with a C compiler.






Discussion
Ask a question about 'C standard library'
Start a new discussion about 'C standard library'
Answer questions from other users
Full Discussion Forum



Encyclopedia


The C standard library consists of a set of sections of the ISO C standard which describe a collection of header file
Header file

In computer programming, particularly in the C and C++ programming languages, a header file or include file is a computer file, usually in the form of source code, that a compiler automatically includes when processing another source file....
s and library
Library (computer science)

In computer science, a library is a collection of subroutines or Class used to develop software. Libraries contain code and data that provide services to independent programs....
 routines used to implement common operations, such as input/output
Input/output

In computing, input/output, or I/O, refers to the communication between an information processing system , and the outside world ? possibly a human, or another information processing system....
 and string handling, in the C programming language
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
. The C standard library is an interface standard described by a document; it is not an actual library of software routines available for linkage to C programs. No such implementation is properly called C standard library.

Note there is the term C library which may either informally be used as a synonym for C standard library (as in "malloc is the name of a function in the C library"); or may refer to to a particular implementation which provides the C standard library features and other features (as in "this compiler comes with a very reliable C library for ISO C and POSIX programming"); or to any library whatsoever which has an interface for linking to C programs (as in "this software company offers a C library of Fast Fourier Transform functions").

The term C run-time library is used on some platforms to refer to a set of base libraries, which may be distributed in dynamically linkable form with an operating system (with or without header files), or distributed with a C compiler. Another term sometimes used is libc. Not just any library is called the run-time library; run time in this context means the run-time support package associated with a compiler which is understood to make a language complete. The run-time support provides not only the C standard library functions, but possibly other material needed create an environment for the C program, such as initialization prior to the invocation of the main function, or subroutines to provide arithmetic operations missing from the CPU that are needed by code generated by the C compiler.

History

The C programming language
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
, before it was standardized, did not provide built-in functionalities such as I/O operations (unlike traditional languages such as Cobol and Fortran
Fortran

Fortran is a general-purpose programming language, procedural programming language, imperative programming language programming language that is especially suited to numerical analysis and scientific computing....
). Over time, user communities of C shared ideas and implementations of what is now called C standard libraries to provide that functionality. Many of these ideas were incorporated eventually into the definition of the standardized C programming language.

Both Unix
Unix

Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna....
 and C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
 were created at AT&T's Bell Laboratories
Bell Labs

Bell Laboratories is the research organization of Alcatel-Lucent and previously of the American Telephone & Telegraph Company .Bell Laboratories has had its headquarters at Berkeley Heights, New Jersey, and it has research and development facilities throughout the world....
 in the late 1960s and early 1970s. During the 1970s the C programming language became increasingly popular. Many universities and organizations began creating their own variations of the language for their own projects. By the beginning of the 1980s compatibility problems between the various C implementations became apparent. In 1983 the American National Standards Institute
American National Standards Institute

The American National Standards Institute or ANSI is a private non-profit organization that oversees the development of voluntary consensus standards for products, services, processes, systems, and personnel in the United States....
 (ANSI) formed a committee to establish a standard specification of C known as "ANSI C". This work culminated in the creation of the so-called C89 standard in 1989. Part of the resulting standard was a set of software libraries called the ANSI C standard library.

Later revisions of the C standard have added several new required header files to the library. Support for these new extensions varies between implementations.

The headers , , and were added with Normative Addendum 1 (hereafter abbreviated as NA1), an addition to the C Standard ratified in 1995.

The headers , , , , , and were added with C99
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
, a revision to the C Standard published in 1999.

ISO Standard

The ISO C standard library consists of 24 C header files which can be included into a programmer's project with a single directive. Each header file contains one or more function declarations, data type definitions and macros. The contents of these header files follows.

In comparison to some other languages (for example Java
Java (programming language)

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
) the standard library is minuscule. The 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
Container (data structure)

In computer science, a container is a Class , a data structure, or an abstract data type whose instances are collections of other objects. They are used to store objects in an organized way following specific access rules....
" like the C++
C++

C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features....
 Standard Template Library
Standard Template Library

The Standard Template Library is a Library partially included in the C++ C++ standard library. It provides Container s, iterators, algorithms, and Function objects....
, let alone the complete graphical user interface
Graphical user interface

A graphical user interface is a type of user interface which allows people to human-computer interaction such as computers; hand-held devices such as MP3 Players, Portable Media Players or Gaming devices; household appliances and office equipment....
 (GUI) toolkits, networking tools, and profusion of other functionality that Java provides 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 relatively easy.

Many other libraries have been developed to supply equivalent functionality to that provided by other languages in their standard library. For instance, the GNOME
Gnome

A gnome is a mythical creature characterized by its extremely small size and wiktionary:subterranean lifestyle. The word gnome is derived from the New Latin gnomus....
 desktop environment project has developed the GTK+
GTK+

GTK+, or The GIMP Toolkit, is a cross-platform widget toolkit for creating graphical user interfaces. It is one of the most popular toolkits for the X Window System, along with Qt ....
 graphics toolkit and GLib
GLib

In computing, GLib refers to a cross-platform Library . It started off as part of the GTK+ project, however, before releasing version 2 of GTK+, the project's developers decided to separate non-GUI-specific code from the GTK+ platform, thus creating GLib as a separate product....
, a library of container data structures, and there are many other well-known examples. The variety of libraries available has meant that some superior toolkits have proven themselves through history. The considerable downside is that they often do not work particularly well together, programmers are often familiar with different sets of libraries, and a different set of them may be available on any particular platform.

ISO C library headers


<assert.h
Assert.h

assert.h is a header file in the C standard library of the C programming language that defines the C preprocessor Macro assert. The macro implements an assertion , which can be used to verify assumptions made by the program....
>
Contains the assert
Assertion (computing)

In computer programming, an assertion is a First-order logic placed in a program to indicate that the developer thinks that the predicate is always true at that place....
 macro, used to assist with detecting logical errors and other types of bug in debugging versions of a program.
<complex.h
Complex.h

complex.h is a header file in the C standard library of the C programming language that defines functionality for complex arithmetic. These functions use the built-in type complex which was introduced with the C99 revision of C....
>
A set of functions for manipulating complex number
Complex number

In mathematics, the complex numbers are an extension of the real numbers obtained by adjoining an imaginary unit, denoted i, which satisfies:...
s. (New with C99)
<ctype.h
Ctype.h

The header ctype.h in the C standard library for the C contains declaration s for character classification functions.History ...
>
Contains 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 (typically ASCII
ASCII

American Standard Code for Information Interchange , is a coding standard that can be used for interchanging information, if the information is expressed mainly by the written form of English words....
 or one of its extensions, although implementations utilizing EBCDIC
EBCDIC

Extended Binary Coded Decimal Interchange Code is an 8-bit character encoding used on IBM mainframe operating systems such as z/OS, OS/390, VM and VSE , as well as IBM midrange computer operating systems such as OS/400 and i5/OS ....
 are also known).
<errno.h
Errno.h

errno.h is a header file in the C standard library of C . It defines macros to report error conditions through error codes.The errno macro expands to an lvalue with type int, containing the last error code generated in any function using the errno facility....
>
For testing error codes reported by library functions.
For controlling floating-point environment. (New with C99)
<float.h
Float.h

The header float.h in the C Standard Library for the C programming language contains macros that expand to various limits and parameters of the standard floating-point types....
>
Contains defined constants specifying the implementation-specific properties of the floating-point library, such as the minimum difference between two different floating-point numbers (_EPSILON), the maximum number of digits of accuracy (_DIG) and the range of numbers which can be represented (_MIN, _MAX).
<inttypes.h
Inttypes.h

The inttypes.h file is a C header file that is part of the C standard library and API. It was added with the 1999 version of the ISO C standard ....
>
For precise conversion between integer types. (New with C99)
<iso646.h
Iso646.h

The iso646.h header file is part of the C standard library. It was added to this library in a 1995 amendment to the C90 standard. It defines a number of macros which allow programmers to use C bitwise and logical Operator , which, without the header file, cannot be quickly or easily typed on some international and non-QWERTY keyboards....
>
For programming in ISO 646 variant character sets. (New with NA1)
<limits.h
Limits.h

limits.h is the header of the general purpose standard library of the C programming language which includes definitions of the characteristics of common variable types....
>
Contains defined constants specifying the implementation-specific properties of the integer types, such as the range of numbers which can be represented (_MIN, _MAX).
<locale.h
Locale.h

In computing, locale.h is an C programming language header file, used for purposes of Internationalization and localization. The header provides two key function: localeconv and setlocale....
>
For setlocale and related constants. This is used to choose an appropriate locale
Internationalization and localization

In computing, internationalization and localization are means of adapting computer software to different languages and regional differences. Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes....
.
<math.h
Math.h

math.h is a header file in the C standard library of C programming language designed for basic mathematical operations. Most of the functions involve the use of floating point numbers....
>
For computing common mathematical functions
<setjmp.h
Setjmp.h

setjmp.h is a header file defined in the C standard library to provide "non-local jumps," or control flow besides the usual subroutine call and return sequence....
>
Declares the macros setjmp and longjmp, which are used for non-local exits
<signal.h
Signal.h

signal.h is a header file defined in the C Standard Library to specify how a program handles Signal_ while it executes. A signal can report some exceptional behavior within the program , or a signal can report some asynchronous event outside the program ....
>
For controlling various exceptional conditions
<stdarg.h
Stdarg.h

is a header in the C standard library of the C programming language that allows functions to accept an indefinite number of arguments....
>
For accessing a varying number of arguments passed to functions.
<stdbool.h
Stdbool.h

The header stdbool.h in the C Standard Library for the C programming language contains four macros. This header was introduced in C99.The macros as defined in IEEE Std 1003.1-2001 are :...
>
For a boolean data type. (New with C99)
<stdint.h
Stdint.h

stdint.h is a header file in the C standard library introduced in the C99 standard library section 7.18 to allow programmers to write more portable code by providing a set of typedefs that specify exact-width integer types, together with the defined minimum and maximum allowable values for each type, using macros....
>
For defining various integer types. (New with C99)
<stddef.h
Stddef.h

stddef.h is a header file in the standard library of the C programming language which defines the macro NULL and the types ptrdiff_t, wchar_t, and size_t....
>
For defining several useful types and macros.
<stdio.h
Stdio.h

stdio.h, which stands for "standard C file input/output header", is the header file in the C C standard library that contains macro definitions, constants, and declarations of functions and types used for various standard input and output operations....
>
Provides the core input and output capabilities of the C language. This file includes the venerable printf
Printf

The class of printf functions is a class of function , typically associated with curly bracket programming languages, that accept a string parameter which specifies a method for rendering a number of other parameters into a string....
function.
<stdlib.h
Stdlib.h

stdlib.h is the header of the general purpose standard library of C programming language which includes functions involving memory allocation, process control, conversions and others....
>
For performing a variety of operations, including conversion, pseudo-random numbers
Pseudorandom number generator

A pseudorandom number generator is an algorithm for generating a sequence of numbers that approximates the properties of random numbers. The sequence is not truly random in that it is completely determined by a relatively small set of initial values, called the PRNG's state. Although sequences that are closer to truly random can be gen...
, memory allocation, process control, environment, signalling, searching, and sorting.
<string.h
String.h

string.h is the header in the C standard library for the C programming language which contains Macro definitions, constants, and declarations of functions and types used not only for String handling but also various memory handling functions; the name is thus something of a misnomer....
>
For manipulating several kinds of strings.
<tgmath.h
Tgmath.h

tgmath.h is a Standard C header that defines many type-generic macro that can be used for a variety of mathematical operations. This header also includes math.h and complex.h....
>
For type-generic mathematical functions. (New with C99)
<time.h
Time.h

In the C and C++ programming languages, time.h is a header file defined in the C Standard Library to declare system time functions that provide standardized access to time/date manipulation and formatting....
>
For converting between various time and date formats.
<wchar.h
Wchar.h

wchar.h is a header file in the C Standard Library, part of a 1995 extension to the C standard. It contains extended multibyte and wide character utilities....
>
For manipulating wide streams and several kinds of strings using wide characters - key to supporting a range of languages. (New with NA1)
For classifying wide characters. (New with NA1)


The C standard library in other languages

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 operation semantics are kept similar. The C++
C++

C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features....
 programming language, for example, includes the functionality of the ANSI C standard library in the namespace std (like stdprintf, stdatoi, stdfeof, etc.), in header files with similar names to the C ones ("cstdio", "cmath", "cstdlib", etc). Other languages that take similar approaches are D
D (programming language)

The D programming language, also known simply as D, is an Object-oriented programming, Imperative programming, Multi-paradigm programming language system programming language by Walter Bright of Digital Mars....
 and the predominant implementation of Python
Python (programming language)

Python is a general-purpose high-level programming language. Its design philosophy emphasizes code readability. Python's core syntax and semantics are Minimalism , while the standard library is large and comprehensive....
 known as CPython
CPython

CPython is the default, most-widely used implementation of the Python . It is written in C . In addition to CPython, there are two other production-quality Python implementations: Jython, written in Java , and IronPython, which is written for the Common Language Runtime, as well as several experimental implementations....
. In the latter, for example, the built-in file object is defined as "implemented using C's stdio package", so that the available operations (open, read, write, etc.) are expected to have the same behavior as the corresponding C functions.

Compiler built-in functions


Some compilers (for example, GCC
GNU Compiler Collection

The GNU Compiler Collection is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain....
) provide built-in versions of many of the functions in the C standard library; that is, the implementations of the functions are written into the compiled object file
Object file

In computer science, object code, or an object file, is the representation of code that a compiler or assembler generates by processing a source code file....
, and the program calls the built-in versions instead of the functions in the C library shared object file. This reduces function call overhead, especially if function calls are replaced with inline
Inline function

In computer science, an inline function is a programming language construct used to suggest to a compiler that a particular function be subjected to inline expansion; that is, it suggests that the compiler insert the complete body of the function in every context where that function is used....
 variants, and allows other forms of optimisation
Compiler optimization

Compiler optimization is the process of tuning the output of a compiler to minimize or maximize some attribute of an executable computer program....
 (as the compiler knows the control-flow
Control flow

In computer science control flow refers to the order in which the individual statement , Instruction or function calls of an imperative programming or functional programming computer program are execution or evaluated....
 characteristics of the built-in variants), but may cause confusion when debugging (for example, the built-in versions cannot be replaced with instrumented
Instrumentation (computer programming)

In context of computer programming, instrumentation refers to an ability to monitor or measure the level of a product's performance, to diagnose errors and writing trace information....
 variants).

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 unit in the program, these two pointers must compare equal; that is, the address comes by resolving the name of the function, which has external (program-wide) linkage.

POSIX standard library

POSIX
POSIX

POSIX or "Portable Operating System Interface" is the collective name of a family of related standardizations specified by the Institute of Electrical and Electronics Engineers to define the application programming interface , along with shell and utilities interfaces for software compatible with variants of the Unix operating system, altho...
 (and SUS
Single UNIX Specification

The Single UNIX Specification is the collective name of a family of standards for computer operating systems to qualify for the name "Unix". The SUS is developed and maintained by the Austin Group, based on earlier work by the IEEE and The Open Group....
) specifies a number of routines that should be available over and above those in the C standard library proper; these are often implemented alongside the C standard library functionality, with varying degrees of closeness. For example, glibc implements functions such as fork
Fork (operating system)

In computing, when a Computer_process forks, it creates a copy of itself, which is called a "Child_process." The original process is then called the "Parent_process"....
 within libc.so, but before NPTL was merged into glibc it constituted a separate library with its own linker flag. Often, this POSIX-specified functionality will be regarded as part of the library; the C library proper may be identified as the ANSI or ISO
International Organization for Standardization

The International Organization for Standardization , widely known as ISO , is an international standard-setting body composed of representatives from various national standards organizations....
 C library.

Implementations


Unix-like systems typically have a C library in shared library form, but the header files (and compiler toolchain) 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. The C 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 languge, but also de facto part of the operating system interface. Unix-like operating systems generally cannot function if the C library is erased.

By contrast, on Microsoft Windows, the core system dynamic libraries (DLL
DLL

DLL is an abbreviation which can commonly mean:* Data link layer, a layer in the OSI network architecture model* Delay-locked loop, a device to reduce clock skew in digital circuits...
's) do not provide an implementation of the C standard library; this is provided by each compiler individually. 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 targetted systems. Functions in a compiler's C library are not regarded as interfaces to Microsoft Windows.

Many other implementations exist, provided with both various operating systems and C compilers.

Although there exist too many implementations to list, some popular implementations follow:

  • BSD libc, implementations distributed under BSD
    Berkeley Software Distribution

    Berkeley Software Distribution is the Unix operating system derivative developed and distributed by the Computer Systems Research Group of the University of California, Berkeley, from 1977 to 1995....
     operating systems.
  • GNU C Library
    GNU C Library

    The GNU C Library, commonly known as glibc, is the C standard library released by the GNU Project. Originally written by the Free Software Foundation for the GNU operating system, the library's development has been overseen by a committee since 2001, with Ulrich Drepper from Red Hat as the lead contributor and maintainer....
    , the most common implementation used in Unix-like
    Unix-like

    A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....
     systems such as GNU
    GNU

    GNU is a computer operating system composed entirely of free software. Its name is a recursive acronym for GNU's Not Unix; it was chosen because its design is Unix-like, but differs from Unix by being free software and containing no Unix code....
    /Linux
    Linux

    Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the GNU GPL license...
    .
  • Dinkum C99 Library from Dinkumware
    Dinkumware

    Dinkumware is a software company specializing in core libraries for C /C++.The company has provided the Standard C++ STL library shipped with Microsoft Visual_C_Plus_Plus and claims to be the leading supplier of C++ and Embedded C++ libraries to the embedded community....
    , most common commercially licensed one
  • Microsoft C Run-time Library, an implementation of Dinkumware' Dinkum C++ Library
  • dietlibc
    Dietlibc

    dietlibc is a C standard library released under the GNU General Public License Version 2. It was developed by Felix von Leitner with the goal to compile and link programs to the smallest possible size....
    , an alternative small implementation of the C standard library
  • uClibc
    UClibc

    In computing, uClibc is a small C standard library intended for embedded Linux systems. uClibc was created to support uClinux, a version of Linux not requiring a memory management unit and thus suited for microcontrollers ....
    , a C standard library for embedded Linux
    Linux

    Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the GNU GPL license...
     systems (MMU-less)
  • Newlib
    Newlib

    Newlib is a C standard library implementation intended for use on embedded systems. It is a conglomeration of several library parts, all under free software licenses that make them easily usable on embedded products....
    , a C standard library for embedded systems (MMU-less)
  • klibc
    Klibc

    The klibc is a minimalistic C standard library subset developed by Peter Anvin, intended to be used within an initramfs, as part of a multi-stage Linux boot process....
    , primarily for booting Linux systems.
  • EGLIBC, variant of glibc for embedded systems.


See also

  • List of C functions
    List of C functions

    This page aims to alphabetically list all the predefined subroutine used in the C standard library, and a few of the non-standard functions.* assert.h...
  • C++ standard library
    C++ standard library

    In C++, the Standard Library is a collection of class and subroutine, which are written in the core language. The Standard Library provides several generic containers, functions to utilise and manipulate these containers, function objects, generic strings and streams , support for some language features, and every day functions for tasks suc...


External links

  • : A detailed description of the header files
  • Microsoft on MSDN
  • NetBSD and : A good academic reference.