# Ch 14: Chunks of Bytecode

> Study guide to Crafting Interpreters chapter 14. Start of clox: a C project with a dynamic array of bytecode (a chunk), a constant pool, line information, a…

Updated October 20, 2026.

## Summary {#summary}

Crafting Interpreters chapter 14, Chunks of Bytecode: Start of clox: a C project with a dynamic array of bytecode (a chunk), a constant pool, line information, a disassembler and a memory reallocation function used for all allocation. Budget about 5 hours; it is a reading chapter, with no tests to pass.

## Key facts {#key-facts}

- Week 12 of 145 on the cracked.guide path, in [Crafting Interpreters](https://cracked.guide/crafting-interpreters).
- Time budget: about 5 hours.
- Part of the book: clox (bytecode VM, C).
- No test suite for this chapter: you mark it done yourself.
- 3 challenges at the end of the chapter.
- Terms it teaches: [clox](https://cracked.guide/glossary/clox), [Bytecode VM](https://cracked.guide/glossary/bytecode-vm).

## Week 12 goals {#objectives}

By the end of week 12 you can:

- Implement a growable chunk of bytecode with a constant pool and line info.
- Explain how OP_CONSTANT uses a one-byte operand to index the constants.
- Use the disassembler to read each instruction and its byte offset.

## This week's steps {#steps}

- Read the chapter: Compile with warnings on (-Wall -Wextra) and use AddressSanitizer (-fsanitize=address) from day one.
- Write the code in your lox repo: Type it into clox/ (C) yourself as you read, and get it running.
- Do the challenges (1–3): Challenge 1 (compress line info, for example with run-length encoding) and challenge 2 (add a long constant instruction for more than 256 constants) are both worth doing.

## Why it matters {#why}

Bytecode is how CPython, Lua, the JVM and many other runtimes execute code. This chapter is also a crash course in writing careful C.

## How to approach it {#approach}

Compile with warnings on (-Wall -Wextra) and use AddressSanitizer (-fsanitize=address) from day one. Build the disassembler and use it constantly.

## Challenges {#challenges}

3 challenges at the end of the chapter.

Challenge 1 (compress line info, for example with run-length encoding) and challenge 2 (add a long constant instruction for more than 256 constants) are both worth doing. Challenge 3 (write your own allocator) is a big stretch; save it for later or connect it to Knuth 2.5.

## Common traps {#traps}

- Forgetting to update capacity or count when growing an array.
- Reading freed memory after a reallocation moves the array. AddressSanitizer catches this.
- Missing include guards or mixing up .h and .c responsibilities.

## Links {#links}

- [Read the chapter: Ch 14: Chunks of Bytecode](https://craftinginterpreters.com/chunks-of-bytecode.html)
- [Official repo: book source, both interpreters, test suite](https://github.com/munificent/craftinginterpreters)
- [Wikipedia: Bytecode](https://en.wikipedia.org/wiki/Bytecode)
- [Hacker News: Bytecode VMs in surprising places](https://news.ycombinator.com/item?id=48236122)

---

Source: https://cracked.guide/guide/ci-14
cracked.guide: A free, dated 145-week path to getting genuinely cracked at programming.
