C Library: Difference between revisions
[unchecked revision] | [unchecked revision] |
Added details, fixed PDClib url, fixed broken urls. |
Improved the Types section (and changed its name to the more appropriate Versions) as there were complaints on the discussion page. |
||
Line 3: | Line 3: | ||
The ''C standard library'' provides basic functionality such as string manipulation, basic I/O, and memory allocation. Whether you're writing a kernel in C or you plan on supporting existing C programs, you'll want to use it. |
The ''C standard library'' provides basic functionality such as string manipulation, basic I/O, and memory allocation. Whether you're writing a kernel in C or you plan on supporting existing C programs, you'll want to use it. |
||
== |
==Versions== |
||
The C standard describes two versions of the |
The C standard describes two versions of the standard library: the, complete, hosted library and the freestanding one, providing only a subset of the hosted library that doesn't need to interact with the environment. System software should typically use the former, while applications should have the latter available. |
||
The <tt>__STDC_HOSTED__</tt> macro expands to <tt>1</tt> on hosted implementations, or <tt>0</tt> on freestanding ones. The freestanding headers are: <tt><float.h></tt>, <tt><iso646.h></tt>, <tt><limits.h></tt>, <tt><stdalign.h></tt>, <tt><stdarg.h></tt>, <tt><stdbool.h></tt>, <tt><stddef.h></tt>, <tt><stdint.h></tt>, and <tt><stdnoreturn.h></tt>. Note that not all their functionality is available in the freestanding mode. |
|||
GCC defaults to a hosted implementation, but can switch to a freestanding one with the <tt>-ffreestanding</tt> argument. |
|||
==Implementations== |
==Implementations== |
Revision as of 14:14, 2 September 2012
The C standard library provides basic functionality such as string manipulation, basic I/O, and memory allocation. Whether you're writing a kernel in C or you plan on supporting existing C programs, you'll want to use it.
Versions
The C standard describes two versions of the standard library: the, complete, hosted library and the freestanding one, providing only a subset of the hosted library that doesn't need to interact with the environment. System software should typically use the former, while applications should have the latter available.
The __STDC_HOSTED__ macro expands to 1 on hosted implementations, or 0 on freestanding ones. The freestanding headers are: <float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, <stdint.h>, and <stdnoreturn.h>. Note that not all their functionality is available in the freestanding mode.
GCC defaults to a hosted implementation, but can switch to a freestanding one with the -ffreestanding argument.
Implementations
There exists a myraid of implementations of the standard library avalible at your disposal. Using one may be a viable solution but you may instead wish to roll your own.
There is a comparison table of some of these at: [1]
Newlib
- The license is unrestricted (not GPL or LGPL), but each file likely has a different copyright notice.
- newlib website
GlibC
- Should be absolutely complete
- GPL license
- glibc website
Solar's PDCLib
- Under active development, and not at full working release 1.0 yet
- Creative Commons Zero license (basically public domain)
- PDCLib website
microClibC
- LGPL license
- uclibc website
Musl
- MIT license (basically public domain)
- musl website
diet libc
- GPL license
- dietlibc website
Caprice
- MIT license (basically public domain)
- ccaprice website
Google's Bionic
- BSD license (basically public domain)
- no support for locales
- no support for wide chars (i.e. multi-byte characters)
- no libthread_db or libm implementation
- its own smallish implementation of pthreads based on Linux futexes
- support for x86, ARM and ARM thumb CPU instruction sets and kernel interfaces
Standards
Especially if you want to roll your own C lib, you may want to buy the ISO/IEC 9899 specification to work from. It is not free. Expect a PDF to cost somewhere around $250 (US) or 250 Swiss Francs, depending on currency conversions.
The older standards (C89/C90, C99) are not commercially available anymore. To find the current standard, go to one of the following sites and search for document "ISO/IEC 9899".
- Specification Stores: