6 comments

  • WanderZil an hour ago ago

    Nice that dropping a `result` is a compile error unless you explicitly cast it to void, unlike C's default of silently ignoring return codes.

  • teo_zero 7 hours ago ago

    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?

  • onlyrealcuzzo 14 hours ago ago

    > Of course there is Swift, Ocaml or Rust

    Presumably C++ is the first thing you should mention.

  • adsharma 14 hours ago ago

    Why not use vlang?

    I wanted to do the same thing to python. So wrote a parser for a variant of python.

    It's spy-ast on pypi

  • stass 2 days ago ago

    Realized that the post is a bit light on numbers, so here're some.

    I rewrote the parser of tomlc99 (2k lines) in Type-C as a test. I used result/try/defer for the error paths and left everything else unchanged, linking against the same C programs and tests.

    Doing fault injection with one failed allocation per run over ~1500 runs: the original C went wrong in 34 (25 leaks, 9 use-after-free); the rewrite went wrong never, sanitizers clean.

    With original toml-spec-tests files: the original leaked in 1002 of them and crashed in 9; the rewrite did neither.

    This is an example of how the code looks like for an expression evaluator: type expr = | Num(int value) | Add(const expr l, const expr r) | Mul(const expr l, const expr r) | Div(const expr l, const expr r);

      static result(int, eval_error)
      eval(const expr *e)
      {
          int d;
    
          match (*e) {
          case Num(value):
              return (Ok(value));
          case Add(l, r):
              return (fit((long long)try eval(l) + try eval(r)));
     …
    
    Happy to answer any questions!
  • Panzerschrek 9 hours ago ago

    Yet another project adding bells and whistles into C without solving its core issues. Now vibe-coded.