C Reference
|
This section documents C23 (ISO/IEC 9899:2024), per ISO/IEC JTC1/SC22/WG14’s freely available working draft N3220, which WG14 documents as differing from the published standard only editorially — the reference these pages are written and verified against. This content was generated with the assistance of AI and should be verified against the WG14 draft and cppreference.com’s C reference before being relied on in production. This section’s bibliography lists the reference material consulted while preparing these pages. |
Welcome to the C reference. C is a small, statically-typed, compiled systems language: a handful of built-in types, explicit control over memory, and a thin standard library that maps closely onto what the machine and the operating system actually do. Designed by Dennis Ritchie at Bell Labs in the early 1970s to write Unix, it has been an ISO standard since 1989 and remains the language whose ABI virtually every other language uses to talk to the outside world. This section documents C23 (ISO/IEC 9899:2024), written and verified against WG14’s freely available working draft N3220, and flags C23-only features together with their C17/C11 fallbacks.
If you are new to C, read Getting Started and
Program Structure first, then the Language fundamentals
pages in order, followed by Pointers and memory — those two groups are what C is. From there the remaining
groups (the preprocessor and generic programming, the standard library, robustness and performance,
concurrency, and tooling and standards) can be read in any order as you need them. Every code example in this
section compiles cleanly with clang -std=c23 -Wall -Wextra.
This site also documents C++, which began as "C with Classes" and still shares C’s declaration syntax, type model and standard library — while being neither a strict superset of C nor standardized by the same committee. Each page below links to its nearest C++ counterpart under See Also; for the relationship in one place, including a page-by-page map and the list of valid C that C++ rejects, see C and C++ on the C++ Reference landing page.
What’s covered
Getting started
-
Getting Started — what C is, the standard editions from K&R to C23, the major compilers, "Hello, World", and compiling with
-std=c23 -Wall -Wextra. -
Program Structure — declarations vs. definitions, translation units and headers, the translation phases, `main’s signatures, and exit status.
Language fundamentals
-
Lexical Structure and Style — character sets, comments, identifiers and reserved names, the C23 keyword list, every literal form, attribute syntax, and the formatting conventions.
-
Basic Types and Values — the abstract state machine,
bool, character and integer types,<stdint.h>and_BitInt, floating-point types, the integer promotions and the conversion traps. -
Constants, Enumerations and Initialization —
const,enumwith C23 fixed underlying types, macros vs.constexpr, compound literals, every initializer form, andstatic_assert. -
Operators and Expressions — arithmetic, integer division, bitwise and shift operators, the precedence table, lvalues, and evaluation order and sequencing.
-
Control Flow —
if/else,switchand fall-through, the three loop forms,break/continue,gotofor cleanup, andreturn. -
Functions — prototypes, pass-by-value, array parameters, recursion,
staticandinline,[[noreturn]], and variadic functions. -
Arrays and Strings — array length and
sizeof, multidimensional and variable-length arrays, array-to-pointer decay, string literals, and the<string.h>essentials. -
Structures, Unions and Type Aliases —
structand designated initialization,typedef, tagged unions, bit-fields, flexible array members, and alignment and padding.
Pointers and memory
-
Pointers — address-of and dereference, pointer arithmetic, validity and dangling pointers,
nullptr,void *,constandrestrict, and function pointers. -
Memory Model and Alignment — object representation, type punning, effective types and strict aliasing, and
alignas/alignof. -
Dynamic Memory Allocation —
malloc/calloc/realloc/free, growable arrays, ownership rules, and the classic defects. -
Storage Duration, Scope and Linkage — the four storage durations, the scopes, internal vs. external linkage, and
thread_local.
Preprocessor and generic programming
-
Preprocessor and Macros — macro hygiene, include guards, conditional compilation,
__has_include, stringification and token pasting,__VA_OPT__, and#embed. -
Type-Generic Programming —
_Genericselection,<tgmath.h>,typeof/typeof_unqual, and C23auto.
Standard library
-
Standard Library Overview — the C23 header catalogue, the interface conventions,
errnodiscipline, Annex K, feature-test macros, assertions, and program termination. -
Numbers and Math —
<inttypes.h>format macros, C23 checked arithmetic and bit utilities,<math.h>,<fenv.h>,<complex.h>, and pseudo-random numbers. -
Input, Output and Files — streams and
FILE, theprintfandscanffamilies,fopenmodes,fread/fwrite, positioning, buffering, and EOF vs. error. -
Strings and Text Processing —
<string.h>and<ctype.h>, numeric conversion,snprintf, locales, UTF-8, and restartable conversions. -
Dates and Times —
time_t,struct timespec,struct tm,strftime,difftime, and measuring elapsed time.
Robustness and performance
-
Error Handling and Program Failure — the catalogue of undefined behavior, state degradation, error codes, cleanup with
goto, assertions, and the sanitizers. -
Advanced Control Flow — sequencing,
goto,setjmp/longjmpandvolatile, and signal handlers with async-signal safety. -
Performance — measuring first, optimization levels,
inline,restrict, the C23 function attributes, profiling, and why undefined behavior is a performance feature.
Concurrency
-
Threads —
<threads.h>,thrd_create/thrd_join,call_once, thread-local storage, mutexes, condition variables and the wait loop, and liveness. -
Atomics and Memory Consistency —
_Atomictypes and<stdatomic.h>, compare-and-exchange, happens-before, the memory orders, fences, and false sharing.
Tooling and standards
-
Build and Tooling — compiler invocation and warning flags, Make and CMake, sanitizers and Valgrind, static analysis,
clang-format, debuggers, and Doxygen. -
Testing —
assert-based checks, a minimal harness, Unity / CMocka / Check / Criterion, CTest, and testing UB-sensitive code under sanitizers. -
C Standards and C23 — the editions timeline, what C23 added and removed, the compiler support matrix, and writing transitional code.
Reference
-
Cheat Sheet (PDF) — a single-page, printable summary of everything in this section, with a downloadable PDF.
Bibliography
-
ISO/IEC 9899:2024 — Programming languages — C — the published C23 standard, and the normative reference for this section (the ISO text itself is a paid document).
-
WG14 N3220 — the C23 working draft — the freely available near-final draft, which WG14 documents as differing from the published standard only editorially. This is the document every page in this section was written and verified against.
-
ISO/IEC JTC1/SC22/WG14 — the C standards committee, and the source for its papers, defect reports and meeting documents.
-
cppreference.com — C reference — the community reference used throughout to cross-check library signatures and semantics, together with its C23 feature page.
-
The GCC manual and GCC’s C standards status page — the primary sources for GCC-specific behavior, extensions and the C23 support matrix.
-
The Clang User’s Manual and Clang’s C language status page — the same for Clang, which is the compiler used to verify every example here.
-
The GNU C Library Reference Manual — the primary source wherever a page discusses libc-specific behavior beyond what the standard specifies.
-
Gustedt, Jens. Modern C, 3rd ed. Manning Publications, 2025. ISBN 9781633437777. Consulted as a reference while preparing these pages — see the publisher’s book page, manning.com, and the author’s freely available manuscript and code archive at gustedt.gitlabpages.inria.fr/modern-c.
The book above is a consulted reference, not the primary source for this section; on any discrepancy, or wherever it is silent on a feature introduced after it was written, the official ISO/IEC 9899:2024 standard and its N3220 working draft win.