News for hackers. Stuff that matters.

Show HN: Type-C – variants, options, generics and pattern matching to C, like TS

https://github.com/stass/type-c

I love C, but often using it for parsing, tree walking or complex error handling leads to spaghetti code.

Of course there is Swift, Ocaml or Rust for situations like that, but then you are either forced to convert the entire codebase, or add a runtime library or go through the pain of bridging C to the new language. Sometimes there are no compilers for the target architecture too when you are working on embedded stuff.

This is where Type-C comes in. It works as a preprocessor like TypeScript and calls the original C driver behind the scenes. Your code stays normal C for the most part, so you can predict how the code will be laid out. TypeC is a full superset of C11, so any C11 code compiles as is.

Want to use TypeC just for one file? Rename to .tc and use the features you want, the rest of the codebase stays the same. This works for kernel or baremetal code too as there is no runtime or extra libararies.

There are examples of TypeC code as well as real-world tests of converting existing code to TypeC on the GitHub page.

Would love to hear your thoughts and feedback!

( no comments | on HN )

There are no comments yet.