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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Ask HN: What one change in C would make it a better language for you?

5 点作者 Decabytes将近 2 年前

12 条评论

stncls将近 2 年前
A very surface change (almost syntactic sugar) that would be neat for me is some form of generics. Specifically, to allow me to implement an algorithm once for different data types. Right now I do it with preprocessor macros and includes; it works but feels wrong.<p>Going deeper, but not as far as changing the language (not hoping for memory safety here), I would like better research and documentation for undefined behavior (UB).<p>I&#x27;m not completely opposed to UB. I understand it is an unfortunate performance&#x2F;safety trade-off that&#x27;s not fully avoidable in a historical language like C. However, there are many types of UB, and for a few of them, the performance benefits feel theoretical (not supported by empirical evidence). I would love some before&#x2F;after benchmarks with the types of UB that can be disabled in the compiler, and some open-minded discussion afterwards.
DLA将近 2 年前
Bounds checks on arrays&#x2F;strings. This would prevent the largest class of errors (buffer overflows) seen in C code.
评论 #36895161 未加载
logicalmonster将近 2 年前
I&#x27;m not sure if that horse could ever be put back in the barn, but I think my mindset for using C would probably feel a lot different if somehow it could be made a strict subset of C++.
didgetmaster将近 2 年前
The default behavior for a case within a switch statement should be to break. If you want to fall through to the next case, it should have been an explicit command (e.g. fallthrough).<p>switch(x) { case 1: DoSomething(); case 2: DoSomethingElse(); case 3: SomePrep(); fallthrough; case 4: DoMore(); default: DoNothing; }<p>Only one statement needed to have case 3 fall through to case 4. No breaks needed at the end of any other cases.
mikewarot将近 2 年前
It&#x27;s not just one, but a short list<p><pre><code> get rid of Macros adopt Pascal style pointer references... @ is an address, p^ is what p points to adopt some form of counted strings, with a null on the end for compatibility adopt Pascal style cast statements, with each path being exclusive (default break)</code></pre>
bjourne将近 2 年前
If the brain-dead implicit type promotion rules were removed. E.g<p><pre><code> unsigned int a = 5; signed int b = -10; bool c = a + b &gt; 0; </code></pre> c is true.
AlectronikLabs将近 2 年前
Modules. No more duplicating code into header files, just import a module like in modern languages. I love C but really hate headers.<p>Then, second for namespaces.
tsukikage将近 2 年前
Namespaces.
sigsev_251将近 2 年前
Defer (which also means lambdas). I really hope that the proposal gets in the next standard.
jjgreen将近 2 年前
&quot;case&quot; variable scope
评论 #36892372 未加载
评论 #36891981 未加载
pestatije将近 2 年前
deprecate headers
akasakahakada将近 2 年前
I ;<p>don&#x27;t;<p>know;