TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: What would a better C look like?

4 点作者 caspervonb超过 6 年前

5 条评论

iamNumber4超过 6 年前
As already mentioned. It exists, D Lang. It’s a better C and a better C++. It has a runtime, which you can choose or not use. It is ABI compatible with C, and C++ ABI is a work in progress.<p>You can switch from writing C to D, and still use all of the existing C libraries and code you do today. You can even use D libraries in your C projects.<p>There is the betterC flag that can be used as well which essentially turns off the D Lang runtime.<p>The runtime allows garbage collection and other memory safety that more modern languages like Java and C# have spoiled use with. Also allowing for write once, compile every where. Making it a very portable language.<p><a href="http:&#x2F;&#x2F;www.dlang.org" rel="nofollow">http:&#x2F;&#x2F;www.dlang.org</a><p>The other benefit is it is a language not owned and developed by a corporation like Java, C#, objective-C and go. So there is no ulterior motive’s or agendas by said corporation.
krapp超过 6 年前
A better C would be C with a few features of C++: function and operator overloading and references. Also metaprogramming... maybe not exactly C++ templates but some sort of macros. Also lambdas.<p>I would also remove the distinction between &#x27;class&#x27; and &#x27;struct&#x27; and just have &#x27;struct&#x27;.<p>I would add the bracket shorthand [] for arrays and {} for maps (and add a map type, maybe.)<p>And honestly, the more I think about it, the more a &quot;better C&quot; starts to look like a &quot;better Lua,&quot; with the ability to return multiple values from a function.
gabrielblack超过 6 年前
Probably nobody needs a &quot;better C&quot; being possible to use C++ in procedural way, avoiding that C parts considered error prone, ugly or dangerous (i.e. using C++ string, smart pointers, etc). However, if we are talking about a different language, not a C improvement, I think Go could be the answer.
评论 #18421035 未加载
Gibbon1超过 6 年前
The three things I can think of are.<p>1. Eliminate all UB<p>2. Ability to strictly define memory layouts<p>3. Ability to safely construct ABI stack frames.
NonEUCitizen超过 6 年前
D with -betterC flag:<p><a href="https:&#x2F;&#x2F;dlang.org&#x2F;spec&#x2F;betterc.html" rel="nofollow">https:&#x2F;&#x2F;dlang.org&#x2F;spec&#x2F;betterc.html</a>