C23 lets you pick an enum's underlying type, shrinking it from 4 bytes to 1

lemire · x · 2026-09-02

Daniel Lemire walks through a practical C23 feature: enums can now declare their underlying type. Traditionally compilers picked int (4 bytes) for something like enum status {OK = 0, ERROR = -1};; in C23 you can write enum status : int8t {...} to use just 8 bits, or widen to uint64t for large values. Useful for reducing or pinning memory layout, verified with staticassert — a technique you can apply immediately.

Original post →

More from coding & agent

coding & agent channel →