# What is clox?

> clox is the bytecode virtual machine for Lox written in C in the second half of Crafting Interpreters, with its own hash table, closures and garbage collector.

**clox**: clox is the bytecode virtual machine for the Lox language, written in C in chapters 14 to 30 of Crafting Interpreters.

**clox** is the second Lox implementation in Crafting Interpreters: a single-pass compiler and a stack-based [bytecode virtual machine](https://cracked.guide/glossary/bytecode-vm) written in C across chapters 14 to 30. It is many times faster than [jlox](https://cracked.guide/glossary/jlox) because it builds everything itself.

## What you build

A dynamic array of bytecode with a constant pool (14), the VM loop (15), an on-demand scanner (16), a [Pratt parser](https://cracked.guide/glossary/pratt-parser) that emits bytecode with no syntax tree (17), value types and strings (18, 19), a hash table with [string interning](https://cracked.guide/glossary/string-interning) (20), globals and locals (21, 22), jumps (23), calls (24), closures with [upvalues](https://cracked.guide/glossary/upvalue) (25), a [mark-sweep garbage collector](https://cracked.guide/glossary/mark-sweep-garbage-collection) (26), classes and methods (27 to 29), and optimizations including [NaN boxing](https://cracked.guide/glossary/nan-boxing) (30).

## Why it is harder than jlox

C gives you nothing for free. You manage every allocation, and a bug in the garbage collector shows up far from its cause. Compile with `-Wall -Wextra -fsanitize=address,undefined` from the first C chapter; it turns mysterious crashes into a line number. On the cracked.guide path clox is weeks 12 to 28.

## Questions

### Do I need to finish jlox before clox?

The book assumes it, because clox explains its design by contrast with jlox. You could start at chapter 14, but you would miss the reasons.

### How fast is clox compared with jlox?

Much faster on the book's benchmarks, because it runs compact bytecode in a tight loop instead of walking Java objects. The exact factor depends on the program.

---

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