TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Help me improve my C-like language, C3

12 pointsby Nuojialmost 5 years ago
I&#x27;m working on a &quot;alternative to C&quot; called C3, but unlike most (e.g. Zig, Odin, Jai, Rust etc) it tries to stay really close to C syntax as far as possible and I&#x27;d love to hear what people like and what they dislike, especially if they write a lot of C.<p>The site here has an overview of the language and code samples: http:&#x2F;&#x2F;www.c3-lang.org<p>You can try it out in the browser here: https:&#x2F;&#x2F;ide.judge0.com&#x2F;?1EFo with the list of implemented features&#x2F;not yet implemented features in the compiler found here: https:&#x2F;&#x2F;github.com&#x2F;c3lang&#x2F;c3c<p>Currently the spec has a bit too many features so I will try to remove the superfluous to make the language more easy to grasp in its entirety.<p>The syntax tries to stay true to C, with things added on top that C can&#x27;t easily add due to backwards compatibility:<p>- Module system<p>- Generics<p>- Semantic Macros<p>- Error handling<p>- Defer<p>- Value methods<p>- Associated enum data<p>- Subtypes (Go&#x27;s embedded structs)<p>- Optional contracts<p>- Built-in strings, maps, subarrays and vararrays<p>P.S. I know the change to use `func` with functions is controversial – it&#x27;s great for a simpler grammar and to make function types stand out, but is quite a departure.<p>P.P.S. &quot;Why not just use C?&quot; Well, we&#x27;re seeing C++ inspired languages (like Rust) taking mindshare both from C++ and C communities. I would like to see an alternative that keeps to the simplicity of C code instead of taking C++ syntactic complexity as a base line.

4 comments

qppoalmost 5 years ago
Here are the things I would need to migrate from C&#x2F;C++&#x2F;Rust to a new language:<p><pre><code> Automatic memory management, with optional manual control, no garbage collection. A universal or widely accepted build system (Cargo, CMake) A public package registry and dependency resolver, designed for deterministic builds, multiple versions of the same package on one machine, etc, and support for private&#x2F;proprietary registries (Cargo, Conan) A modern query-oriented&#x2F;reactive&#x2F;responsive (non-batch) compiler, that supports static analysis, linting, language server features, AST traversals&#x2F;queries, etc. Support for debugging with GDB&#x2F;LLDB. A (substantial) subset of the language with a stable ABI. Fast debug builds, fast release binaries. </code></pre> Syntax&#x2F;semantics of the language are significantly less important to me than all of the above.
评论 #24115475 未加载
gus_massaalmost 5 years ago
<p><pre><code> &#x2F;** * @ensure const(foo), const(bar.x) **&#x2F; </code></pre> Does the compiler see inside comments? I think that Python does that for types because they want to preserve backward compatibility, but I never like it. Why not something like:<p><pre><code> #ensure const(foo), const(bar.x) </code></pre> or<p><pre><code> @ensure const(foo), const(bar.x)</code></pre>
评论 #24109796 未加载
zzo38computeralmost 5 years ago
I might like to have, in a better version of C:<p>- GNU extensions, such as zero-length arrays, ?: with nothing in between, and statements inside of expressions<p>- Less confusing syntax for types<p>- Full LLVM features<p>- Non-Unicode<p>- Both normal include files and token macros, as well as namespacing and hygienic macros supported too<p>- Standard macros for testing alignment, endianness, etc<p>- Macros that can call compile-time execution of codes which can deal with the AST<p>- Reduced runtime requirements<p>- Support for setjmp&#x2F;longjmp with catch blocks; if you longjmp past such a block, it should execute the catch block to clean up as needed before that block jumps again back to the target of the longjmp operation<p>- The goto command.<p>The worst thing about C is I think the confusing syntax for types. Pointer arithmetic and goto are both good, though, so keep those.<p>I can do without automatic memory management.
评论 #24115622 未加载
allochialmost 5 years ago
This is quit interesting project, I&#x27;m loving its direction. Something I hoped for long time ago. I like that it&#x27;s trying to make a better C not eliminating it. Will keep a close eye.