Get the latest tech news

Type-erased generic functions for C: A modest non-proposal


Earlier this year, I read Martin Uecker's proposal N3212 to add parametric polymorphism to C. It's easy to scoff at the idea of adding generic programming to plain C, when C++ already has templates, a…

I think the combination of type-erased generics, paired with a default argument mechanism to collect situationally-appropriate metadata at call sites, could provide a surprising amount of expressivity, allow for better type checking to be retrofitted to existing C interfaces. The default argument mechanism works well for populating metadata parameters from builtin operations like sizeof and alignof, but C as it exists today doesn't provide a way to make open, user-defined associations between types and values. This might be a half-baked idea, but hopefully I've demonstrated that there's some potential here for a generics design that isn't in conflict with some of the nice implementation properties of plain C, preserving the ability to do separate compilation without requiring any additional runtime support.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of proposal

proposal

Photo of type

type

Related news:

News photo

The first proposal for a solar system domain name system

News photo

Proposal Seeks To Replace MySQL With MariaDB By Default For Ubuntu 25.04

News photo

Type 2 diabetes drug associated with 35% lower risk of dementia, study finds