Proven C Book
An Introduction to Modern C with the Proven C Library
draft
rubidus@gmail.comgithub.com/rubidus-api/proven_c_book
An introduction to C, and an introduction to the proven C library.
Written for readers who are just starting out with C.
This edition is a draft. For the paginated index and exact typesetting, see the PDF.
Contents
Part I — Ground
1 Setting the scene2 The regions of memory — where a program puts what3 Programs and processes — what it is to be run
Part II — How computing works
4 A simple model of the machine — the birth of C5 Words and addresses — the archetype of C6 Special knowledge about addresses — address 0, alignment, low bits7 Representing integers — sign, overflow, shift8 Representing numbers — the contract called IEEE 7549 Characters and text — scars in the standard10 The origin of streams — punched cards, line printers, printing terminals11 Memory divides — registers, caches, a ladder of layers12 The machinery of speed — the birth of the standard13 Compiler optimisation — the abstract machine14 And so C is an abstract language
Part III — The first program
15 Hello world16 The general shape of compilation17 Setting up a development environment18 The compiler landscape — C compilers in active service
Part IV — A minimal toolbox
19 The structure of a program20 Expressions and constants — the things that become values21 Using functions — how to call22 Output
Part V — Declarations: how names are made
Part VI — Values and flow
26 The families of types — how the standard divides them27 Integers — a world of finite numbers28 Integer operations — division, bits29 Implicit conversions — promotion and the usual arithmetic conversions30 Booleans and comparison31 Deciding — if and switch32 Repetition — loops and invariants33 The meaning of a function — copying values and side effects34 Assignment and side effects
Part VII — Memory
35 Objects, addresses, pointers36 Null — the three siblings, formally37 The rules of pointers — alignment and provenance38 Arrays39 Multidimensional arrays40 Arrays and pointers — when they are the same and when they are not41 Loop techniques — nesting, escaping, and making a block42 Strings43 Safe input — blocking overflow, handling failure44 Lifetime and storage duration45 Dynamic memory
Part VIII — The shape of data
41 Loop techniques — nesting, escaping, and making a block46 Structs47 Using structs — temporary values, named arguments, layout48 Unions and representation
Part IX — Deep corners
49 Expressions and operators50 Real numbers — the mathematics of approximation51 Errors and contracts52 Undefined behaviour
Part X — Structure
53 The three faces of main — entry point and exit status54 Several files — splitting and linking55 The world of names — four name spaces and three axes56 Handling name collisions — from prefixes to namespace57 The preprocessor and the translation phases58 Variadic functions59 Functions as values — the function pointer60 How to read a declaration — two readings and typedef61 The terrain of the standard library
Part XI — Reading the standard library
62 The standard library at a glance63 Streams in reality — <stdio.h> ①64 The traps of reading and writing — <stdio.h> ②65 Strings and memory — <string.h>66 The drawer of odds and ends — <stdlib.h>67 Character classification — <ctype.h>68 Locales ① — a program’s regional settings69 Locales ② — numbers, money, time and sorting70 Wide characters ① — wchar_t and multibyte conversion71 Wide characters ② — the platforms, and wide I/O72 In practice — handling Unicode and multibyte encodings73 Numbers — <math.h>, <fenv.h>, <tgmath.h>74 Time — <time.h>75 Diagnosis and control — <errno.h>, <assert.h>, <signal.h>, <setjmp.h>76 Signals — <signal.h>77 Non-local jumps — <setjmp.h>78 What the new standards added, and the *_s controversy79 Running in separate strands — <threads.h>80 Operations that do not split — <stdatomic.h>81 How to ask about overflow — <stdckdint.h>82 From macro to keyword — bool, nullptr and their companions83 A program’s memory layout — operating systems and embedded84 Inside the allocator — the heap, alternative allocators, alternative standard libraries
Part XII — proven — a new, stable foundation
85 The five bugs shipped for fifty years86 Getting started with proven87 Errors are values88 The foundation — bytes, views, and arithmetic that does not overflow89 Allocation is a parameter90 Strings and text91 Formatting and parsing — not writing the type twice92 Containers and algorithms93 The outside world — files, streams, time, random numbers94 The boundaries — running things overlapped, and when there is no OS95 Writing it three times — a tiny JSON
Part XIII — Closing
96 C in practice — tools, projects, and territories97 The embedded toolbox — compilers and the tools beside them98 Modern C, gathered up
Front and back matter
Appendix A — Operator lookupAppendix B — printf and scanf formats in fullAppendix C — Implicit conversions in summaryAppendix D — Further reading, tools, and the standard documentAppendix E — How grammar is written (EBNF) and the whole C grammarAppendix F — The standard library, entry by entryBibliography and sourcesIndex