Get the latest tech news

Generic Containers in C: Vec


Martin Uecker, 2025-07-20 I discuss the implementation of type and bounds safe generic containers in C. Previously, I discussed a span type, and bounds checking using arrays.

It is very similar to the span type I discussed two weeks ago and you may want to read this post first. On top of this interface I have another version that always assumes that the available capacity is the current size rounded up to the next power of two (at least below a certain limit). I would usually write a loop, but I wanted to show how one can continue to do bounds safe processing with the array that represents the vector.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Vec

Vec

Photo of Generic Containers

Generic Containers