Skip to content

Instantly share code, notes, and snippets.

View alurm's full-sized avatar

Alan Urmancheev alurm

View GitHub Profile
@alurm
alurm / README.md
Last active June 13, 2026 02:54
A generic dynamic array in C that stores no capacity and needs no struct

A generic dynamic array in C that stores no capacity and needs no struct

The following header shows a way to make a generic dynamic array in C with an array of two pointers:

  • the first pointer stores the length of the dynamic array;
  • the second pointer points to the data.

So, int *vec[2] = { 0 }; is an empty dynamic array of ints. struct person *people[2] = { 0 }; is an empty dynamic array of people.

(uintptr_t)vec[0] is the length of the array, vec[1] is the array.