liveBook · Manning

Null termination

Null termination is the convention of marking the end of a character sequence with a zero-valued character or byte.

How 2 Manning books explain it

Refactoring to Rust

A C string is a contiguous character sequence terminated by a null character.

How it is used
Bridges null-terminated C input into borrowed Rust string slices during C FFI.
How deep it goes
Explains layout, borrowing, allocation avoidance, and UTF-8 validation, but does not develop string parsing beyond conversion.
Examples
Uses a C calculator line buffer, CStr::from_ptr, to_str, and matching pointer addresses to demonstrate shared memory.
What you can do after
Apply it via CStr and to_str to read C-owned input without duplicating its allocation.

Read how Refactoring to Rust explains null termination →

Systems Programming with Zig

A NUL terminator is a zero byte placed after text data to mark the end of a byte string.

How it is used
Bridges Zig string literals to C functions and represents C strings without carrying slice lengths.
How deep it goes
Explains the zero-byte boundary and Zig sentinel-pointer types, while deferring other uses of sentinel values.
Examples
Shows a string literal typed as `*const [21:0]u8` and explains direct C-function passing.
What you can do after
Apply Zig sentinel-pointer types to pass string literals to C functions without copying.

Read how Systems Programming with Zig explains null termination →

Also covered in

What to know first

Related concepts

Questions about null termination

What is null termination?

Null termination is the convention of marking the end of a character sequence with a zero-valued character or byte.

Which Manning books explain null termination?

Refactoring to Rust and Systems Programming with Zig.

What should I know before learning null termination?

Manning books that teach null termination usually introduce slice first.

What is null termination part of?

Null termination is part of C string. A C string is a sequence of character bytes terminated by a zero-valued byte, with its length determined by the terminator rather than stored separately.

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.