liveBook · Manning

Chapter 12: The C memory model

What you will learn in chapter 12 of Modern C, Third Edition

Introduces the C memory model as an abstraction for accessing objects through pointers, while establishing the roles of pointer types and byte-based object representations.

After this chapter you will be able to

What it builds on

Section by section

Introduction

Introduces the C memory model as an abstraction for accessing objects through pointers, while establishing the roles of pointer types and byte-based object representations.

Key terms: C memory model, address, virtual memory, pointer type, base type, object representation, bytes

12.1 A uniform memory model

This section explains how C accounts for every object as bytes, how character types relate to those bytes, and how sizeof reports an object's size.

Key terms: object, byte, unsigned char, unsigned char[sizeof A], char, signed char, character and string data, sizeof operator, sizeof(T), bytes

12.2 Unions

The section uses a union to inspect an unsigned integer’s bytes and explains how their order and size depend on the implementation.

Key terms: union, struct, twofold.val, twofold.bytes, object representation, representation digits, UCHAR_MAX, endianness, little-endian, big-endian

12.3 Memory and state

This section explains how pointer access complicates the program’s abstract state, how aliasing affects optimization, and why avoiding unnecessary address-taking helps.

Key terms: abstract state machine, state, & operator, pointers, aliasing, base type, character types, optimization, alias

12.4 Pointers to unspecific objects

This section explains how void* provides a type-unspecific pointer to an object while preserving its address, and why losing type information calls for caution.

Key terms: object pointer, void*, function pointer, identity operation, void, type information

12.5 Explicit conversions

This section explains why pointer conversions require care, why casts can hide type errors, and when a cast is useful for inspecting an object’s bytes.

Key terms: narrow integer types, int, char, unsigned char, data pointers, void*, qualifier, implicit conversions, cast, unsigned char*

12.6 Effective types

This section explains how effective types restrict access to C objects, including the special cases of unions and character types, and why the restriction helps compilers reason about aliasing.

Key terms: effective type, variable, compound literal, character type, union, effective union type, member, byte representation, unsigned char, array of unsigned chars

12.7 Alignment

This section explains why object alignment matters when converting character pointers and introduces C's alignment operators and their limits.

Key terms: alignment, word boundary, pointer cast, bus error, alignof, alignas, effective type rule, _Alignof, _Alignas

12.8 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 11: Pointers Chapter 13: Storage →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.