C Mastery / Standard Library Overview and Headers
Part 3 — The Standard Library

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

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:

HeaderPurpose
<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

not).

Undefined Behavior

overlapping buffers to memcpy) is generally UB. Each function's requirements are covered in its chapter.

Portability

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

behavior.

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?

References

Verification

verified.`

Progress

Concept checkboxes

Mastery levels

ConceptCurrent level (0–8)Target level
c.lib.overview05