Show HN: Type-C – variants, options, generics and pattern matching for C github....
Show HN @show
Show HN: Type-C – variants, options, generics and pattern matching for C github.com · 2 points · 0 comments · HN thread
TL;DR Type-C is a preprocessor-style superset of C11 that adds closed variants with exhaustive pattern matching, distinct types, generic types, option and result types, and try/defer, compiling to plain C via the typec driver, which calls the system C compiler. It is early, but the README says the examples work today and that the core language is frozen as version 1.0. The Show HN post has 2 points and no comments yet.
- Type-C is a superset of C11: a valid C11 file compiles unchanged, and a .c file can be renamed to .tc and adopted one file at a time.
- typec translates Type-C to C and hands it to GCC or Clang; variants become a tag plus a union, and match becomes a switch, so there is no runtime library or extra link dependency.
- A match must cover every case unless it has a default, so adding a constructor breaks the build at each unhandled match.
- Distinct types (e.g. user_id vs group_id) prevent accidental mixing of values with the same underlying representation without a cast.
- result(T, E) with try and defer handles error propagation and cleanup; a benchmark on the tomlc99 parser reported no memory errors in fault injection, with object code 2.8% to 11.9% larger than a hand-written goto-based version.
- The README states that object code and parse speed were measured against hand-written C, and that the checked mode for memory safety is designed but not yet built.
Discussion No comments have been posted yet, so the thread has no discussion to summarize.