C Library: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content deleted Content added
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.


==Types==
==Versions==


The C standard describes two versions of the C 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 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>&lt;float.h&gt;</tt>, <tt>&lt;iso646.h&gt;</tt>, <tt>&lt;limits.h&gt;</tt>, <tt>&lt;stdalign.h&gt;</tt>, <tt>&lt;stdarg.h&gt;</tt>, <tt>&lt;stdbool.h&gt;</tt>, <tt>&lt;stddef.h&gt;</tt>, <tt>&lt;stdint.h&gt;</tt>, and <tt>&lt;stdnoreturn.h&gt;</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

This page is a stub.
You can help the wiki by accurately adding more contents to 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 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

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

Musl

diet libc

Caprice

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".