C Library

From OSDev.wiki
Revision as of 05:57, 3 September 2012 by Solar (talk | contribs) (→‎Versions: fare-well edit. ;-))
Jump to navigation Jump to search
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>.

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