logoalt Hacker News

teo_zero • today at 6:47 AM • 1 reply • view on HN

I like it, but I have a couple of questions.

Why C11? We're in 2026, we should target C23 at least, with a forward look at C2y.

Why the keyword "type"? Can't the same functionality be added within a typedef statement? Is there a reason why "|" can't be recognized wherever a type is expected?

And finally, the name "Type-C"... Isn't it already closely associated with USB connectors?


Replies

stass • today at 8:05 AM

> Why C11? We're in 2026, we should target C23 at least, with a forward look at C2y.

Mostly compiler support. I wanted for it to work with a wide range of compilers, so didn't want to introduce a dependency on C23 or beyond. Having said that, I expect Type-C to any C23 code as well, but I haven't systematically tested that.

Basically it's designed to support any somewhat recent random ass compiler as a backend, like GCC for SH4.

> Why the keyword "type"? Can't the same functionality be added within a typedef statement?

This would be tricky. In C typedef creates an alias for an existing type, not a new type, so overloading typedef would make it mean two different things depending on the context. A more technical reason is that typedef puts the new name last where is Type-C needs it come first so it can be used in recursive types like e.g. "type expr = | Num(long v) | Add(expr l, expr r)". This is the reason C itself needs forward declaration for structs for recursive types.

A new keyword, type, costs nothing as Type-C only recognizes it at the beginning of declarations which is not a valid C anyway.

> Is there a reason why "|" can't be recognized wherever a type is expected?

It can, but that would be challenging and ROI is unclear. Right now variant types are nominal, so the same "A(int)|B" type in two places will be treated as two separate types. Making variant types structural, especially across multiple .tc modules, is... not even sure it's even possible to build the way Type-C is built. C code Type-C generates also needs a name for the C type and currently that comes from the declared Type-C type. Anonymous types will need a stable name across interfaces, so typec compiler will need to parse the entire codebase or become a standalone compiler instead of emitting C.

> And finally, the name "Type-C"... Isn't it already closely associated with USB connectors?

It came from TypeScript as it's a TypeScript idea applied to C. And having it sound like a Type-C connector seemed like a fun pun.