Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
C standard library
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== 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; in addition to functions specified by the C standard, it includes other functions that are part of the operating system API, such as functions specified in the [[POSIX]] standard. The C library 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 language, but also ''de facto'' part of the operating system interface. Unix-like operating systems generally cannot function if the C library is erased. This is true for applications which are dynamically as opposed to statically linked. Further, the kernel itself (at least in the case of Linux) operates independently of any libraries. On Microsoft Windows, the core system dynamic libraries ([[dynamic-link library|DLLs]]) provide an implementation of the C standard library for the [[Microsoft Visual C++]] compiler v6.0; the C standard library for newer versions of the Microsoft Visual C++ compiler is provided by each compiler individually, as well as ''redistributable'' packages. 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 targeted systems. Functions in a compiler's C library are not regarded as interfaces to Microsoft Windows. Many C library implementations exist, provided with both various operating systems and C compilers. Some of the popular implementations are the following: * The [[BSD libc]], various implementations distributed with [[Berkeley Software Distribution|BSD]]-derived operating systems * [[GNU C Library]] (glibc), used in [[GNU Hurd]], [[GNU/kFreeBSD]], and most [[Linux]] distributions * [[Windows library files#CRT|Microsoft C run-time library]], part of [[Microsoft Visual C++]]. There are two versions of the library: MSVCRT that was a redistributable till v12 / Visual Studio 2013 with low C99 compliance, and a new one UCRT (Universal C Run Time) that is part of Windows 10 and 11, so always present to link against, and is C99 compliant too [https://learn.microsoft.com/en-us/cpp/porting/upgrade-your-code-to-the-universal-crt?view=msvc-170]. * [[dietlibc]], an alternative small implementation of the C standard library (MMU-less) * [[uClibc|μClibc]], a C standard library for embedded [[μClinux]] systems (MMU-less) ** [[uClibc|uclibc-ng]], an embedded C library, fork of μClibc, still maintained, with [[memory management unit]] (MMU) support * [[Newlib]], a C standard library for embedded systems (MMU-less)<ref>{{cite web |url=http://www.cygwin.com/ml/newlib/2006/msg00224.html |title=Re: Does Newlib support mmu-less CPUs? |publisher=Cygwin.com |date=23 March 2006 |access-date=28 October 2011 |archive-url=https://web.archive.org/web/20081122063741/http://www.cygwin.com/ml/newlib/2006/msg00224.html |archive-date=22 November 2008 |url-status=dead}}</ref> and used in the [[Cygwin]] GNU distribution for Windows * [[klibc]], primarily for booting Linux systems * [[musl]], another lightweight C standard library implementation for Linux systems<ref>{{cite web |url=http://www.etalabs.net/musl/ |title=musl libc |publisher=Etalabs.net |access-date=28 October 2011}}</ref> * [[Bionic (software)|Bionic]], originally developed by Google for the Android embedded system operating system, derived from BSD libc * [https://keithp.com/picolibc picolibc], developed by [[Keith Packard]], targeting small embedded systems with limited RAM, based on code from [[Newlib]] and [https://www.nongnu.org/avr-libc/ AVR Libc] === Compiler built-in functions === Some compilers (for example, [[GNU Compiler Collection|GCC]]<ref>{{cite book |author=FSF |author-link=Free Software Foundation |date=2024 |chapter=6.64 Other Built-in Functions Provided by GCC |chapter-url=https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html |title=A GNU Manual |url=https://gcc.gnu.org/onlinedocs/gcc/index.html |publisher=self-published}}</ref>) 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]], 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 function|inline]] variants, and allows other forms of [[compiler optimization|optimization]] (as the compiler knows the [[control flow|control-flow]] characteristics of the built-in variants), but may cause confusion when debugging (for example, the built-in versions cannot be replaced with [[instrumentation (computer programming)|instrumented]] 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 units 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. === Linking, libm === Under FreeBSD<ref>{{cite web |title=Compiling with cc |url=http://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/tools-compiling.html |access-date=2 March 2013}}</ref> and glibc,<ref>{{cite web |last1=Weimer |first1=Florian |title=c - What functions is the libm intended for? |url=https://stackoverflow.com/questions/54054925/what-functions-is-the-libm-intended-for |website=Stack Overflow |access-date=24 February 2021}}</ref> some functions such as sin() are not linked in by default and are instead bundled in the mathematical library [[libm]]. If any of them are used, the linker must be given the directive <code>-lm</code>. POSIX requires that the c99 compiler supports <code>-lm</code>, and that the functions declared in the headers <code>math.h</code>, <code>complex.h</code>, and <code>fenv.h</code> are available for linking if <code>-lm</code> is specified, but does not specify if the functions are linked by default.<ref>{{cite web |title=c99 - compile standard C programs |url=https://pubs.opengroup.org/onlinepubs/9699919799/utilities/c99.html |website=The Open Group Base Specifications Issue 7, 2018 edition |publisher=The Open Group |access-date=24 February 2021}}</ref> musl satisfies this requirement by putting everything into a single libc library and providing an empty libm.<ref>{{cite web |title=musl FAQ |url=https://www.musl-libc.org/faq.html |website=www.musl-libc.org |access-date=24 February 2021}}</ref> === Detection === According to the C standard the macro <code>__STDC_HOSTED__</code> shall be defined to '''1''' if the implementation is hosted. A hosted implementation has all the headers specified by the C standard. An implementation can also be ''freestanding'' which means that these headers will not be present. If an implementation is ''freestanding'', it shall define <code>__STDC_HOSTED__</code> to '''0'''.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)