Implications of writing a freestanding C project

From OSDev Wiki
Jump to: navigation, search

When building an operating system or other freestanding project (that is, a project which for whatever reason cannot link to any of the standard C libraries), you need to remember not to use any of those library functions in the project. Any code that requires functions for which the standard C library is normally used - including all the common stream I/O functions - must be provided as part of the project, or as system-specific library or system calls.

In the case of an operating system, porting the standard libraries is usually a priority, but this leads to a slightly different situation where the compiler on the development host must know to link the correct version of the library for the target system. The usual solution to this is to set up a separate cross compiler for compiling the OS code when the system is not self-hosting. Furthermore, this means that the new system must provide primitive system calls that those libraries can in turn use; the OS itself cannot use the standard library at all, and it is recommended that the OS-specific functions have different names from the standard ones to avoid confusion. This is true for any compiler targeting a different platform or OS, not just GCC; GCC is simply the most common case in OS dev.


Freestanding Headers

The C standard defines freestanding headers. They usually come along with your compiler and can be used in freestanding mode. These headers define data structures, data types, and macros without adding any function prototypes or references to standard functions.

Headers available as of C89


Headers available as of C99


Headers available as of C11


Personal tools