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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

The Development of the C Language

117 点作者 biffa超过 7 年前

4 条评论

Koshkin超过 7 年前
I think it is worth noting that C is special in the sense that compared to other programming languages it is semantically low-level, pretty much on par with assembly. Which is why it offers less opportunity for automatic optimization than most of other languages do.<p>Therefore, just like with assembly, there is nothing too &quot;unfortunate&quot; about the language&#x27;s design (including its &quot;treatment of arrays&quot;), and the fact that C has been, and still remains, highly popular is just the result of healthy competition, IMO.<p>There are a few little things that I wish were different (for example, I see the arrow symbol &#x27;-&gt;&#x27; as noisy and unnecessary - the simple period &#x27;.&#x27; would work with pointers just as well; also, the &quot;semicolon cancer&quot;...), but the language seems to be pretty usable the way it is.
benlorenzetti超过 7 年前
<i>On the other hand, C&#x27;s treatment of arrays in general (not just strings) has unfortunate implications both for optimization and for future extensions. The prevalence of pointers in C programs, whether those declared explicitly or arising from arrays, means that optimizers must be cautious, and must use careful dataflow techniques to achieve good results. Sophisticated compilers can understand what most pointers can possibly change, but some important usages remain difficult to analyze. For example, functions with pointer arguments derived from arrays are hard to compile into efficient code on vector machines, because it is seldom possible to determine that one argument pointer does not overlap data also referred to by another argument, or accessible externally. More fundamentally, the definition of C so specifically describes the semantics of arrays that changes or extensions treating arrays as more primitive objects, and permitting operations on them as wholes, become hard to fit into the existing language.</i><p>Ritchie notes the difficulty with optimization and aliasing and as far as I know the only portable C89&#x2F;99 convention for this is using the appropriate function if what you want to do is memcpy() or memmove().<p>I love C and programming is mostly a hobby for me. But my language experience does not really extend beyond C and C++, other than reading about D, Lisp, Rust, etc. I also think the STL is the beautiful thing C++ gave us, and having it as a library is better than building these structures into the language. The STL relies heavily on iterators of course.<p>My question to HN is: do any languages that really emphasize pointers and iterators over arrays and indices have a non-cumbersome way of telling the compiler when no aliasing is expected? As a hobbyist, I am more interested in something like slices from D or parameter type restrictions than trivially obvious global guarantees like ``if you mutably borrow it then there is no aliasing&#x27;&#x27;. Do D programmers find the slices helpful and easy? Is the syntax and&#x2F;or semantics such that the programmer can provide the compiler with aliasing info? Are there a small number of type concepts for this or does it explode with the number of different data structures.<p>I know there is the restrict keyword, but I have always been too lazy to use it in C and even in C++ it seems (quadratically?) unlikely you would be energetic enough to properly declare which pairs of entities could not alias.
评论 #15139024 未加载
评论 #15140491 未加载
评论 #15139897 未加载
评论 #15138970 未加载
pjmlp超过 7 年前
<i>&quot;Although the first edition of K&amp;R described most of the rules that brought C&#x27;s type structure to its present form, many programs written in the older, more relaxed style persisted, and so did compilers that tolerated it. To encourage people to pay more attention to the official language rules, to detect legal but suspicious constructions, and to help find interface mismatches undetectable with simple mechanisms for separate compilation, Steve Johnson adapted his pcc compiler to produce lint [Johnson 79b], which scanned a set of files and remarked on dubious constructions.&quot;</i><p>Yet it took up all these years until clang for anyone to start taking static analysis seriously in C, and even now many still ignore it.
评论 #15139185 未加载
cntlzw超过 7 年前
I love stories like this. All the history behind a very young but rich science.<p>For example I always assumed C came from a strong typing background and its premises was always about being portable. Neither of them are true.
评论 #15142599 未加载
评论 #15141824 未加载
评论 #15143567 未加载