Standard Library Overview and Headers
This chapter gives an overview of the ISO C standard library: what it is, how it is organized into headers, and how to think about its guarantees and its limits.
Why This Matters
The standard library is where C's real power lies. The core language is small; the library provides I/O, memory management, string handling, math, and more. Knowing what is and is not in the library prevents reinventing it and clarifies what is portable.
Prerequisites
c.core.39— multi-file programs and headers.
Core Concept
What the standard library is
The ISO C standard library is the set of functions, macros, types, and objects that every hosted implementation must provide. It is defined by the C standard, not by a particular operating system. A freestanding implementation provides only a small subset (see c.embedded.1).
The headers
The C17 standard library is organized into these headers:
| Header | Purpose |
|---|---|
<assert.h> | diagnostics (assert) |
<ctype.h> | character classification/conversion |
<errno.h> | error codes (errno) |
<float.h> | floating-point limits |
<limits.h> | integer limits |
<locale.h> | locale |
<math.h> | math functions |
<setjmp.h> | nonlocal jumps |
<signal.h> | signal handling |
<stdarg.h> | variadic functions |
<stddef.h> | common definitions (size_t, NULL, offsetof) |
<stdio.h> | input/output |
<stdlib.h> | utilities (conversion, allocation, etc.) |
<string.h> | string and memory functions |
<time.h> | date and time |
<stdint.h> | fixed-width integer types |
<inttypes.h> | format macros for integers |
<wchar.h> | wide characters |
<wctype.h> | wide character classification |
<stdbool.h> | bool, true, false |
<stdalign.h> | alignas, alignof |
<stdatomic.h> | atomics (C11) |
<threads.h> | threads (C11) |
<stdnoreturn.h> | noreturn (C11) |
<uchar.h> | char16_t/char32_t (C11) |
C23 adds more (e.g., <stdbit.h>, <stdckdint.h>).
How It Works
Headers declare the library's types, macros, and functions. The actual implementation is usually in a separate library that the linker links in automatically (the C runtime library). On hosted systems, the standard library functions may, in turn, call operating-system services (e.g., printf writes via the OS), but the *interface* is standardized.
Variations
Reserved identifiers
When you include a header, the identifiers it declares are reserved. Do not redefine them or use reserved names (see c.core.6).
Library vs. platform
The standard library is part of ISO C. POSIX, Win32, and other platform APIs are separate and not covered by the C standard. This distinction matters for portability.
Common Mistakes
- Assuming a platform function (e.g.,
open,read) is standard C. - Assuming every function is thread-safe (many are, but some like
strtokare
not).
- Redefining a standard identifier after including its header.
Undefined Behavior
- Passing invalid arguments to library functions (e.g.,
NULLtostrlen,
overlapping buffers to memcpy) is generally UB. Each function's requirements are covered in its chapter.
Portability
- The headers and their contents are standard, but the exact implementation and
some behavior (locale, encoding) are implementation-defined.
Under the Hood
The C runtime library is linked into your program. Some functions are thin wrappers over system calls; others are pure library code. The compiler may replace some library calls with built-in optimized versions (e.g., memcpy, strlen).
Practical Usage
- Include only the headers you need.
- Consult the per-function chapters in Part 3 for signatures and failure
behavior.
- Use
<stdint.h>/<inttypes.h>for portable integer code.
Exercises
1. List which of these are ISO C library functions and which are POSIX: printf, open, malloc, strlen, fork, qsort, socket. 2. Write a program that includes <stddef.h> and prints sizeof(size_t) and sizeof(ptrdiff_t). 3. Look up the full list of C17 headers in the standard and compare with the table above.
Deep Challenge
Explain the difference between a hosted and a freestanding implementation's standard library, and list the headers available in freestanding mode. Why does this matter for embedded firmware and OS kernels?
Related Concepts
c.core.3— integer types (stdint.h).c.embedded.1— freestanding environment.c.stdlib.2+ — per-header chapters.
References
- ISO/IEC 9899:2018 §7 (library), §4 (conformance).
Verification
- The header list matches C17 §7.
VERIFIED - Hosted vs. freestanding library distinction.
VERIFIED - No example was executed during generation unless noted. `Execution not
verified.`
Progress
- [ ] Read
- [ ] Understand
- [ ] Complete examples
- [ ] Complete exercises
- [ ] Complete deep challenge
Concept checkboxes
- [ ] Standard library scope
- [ ] Header inventory
- [ ] Hosted vs. freestanding
Mastery levels
| Concept | Current level (0–8) | Target level |
|---|---|---|
| c.lib.overview | 0 | 5 |