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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Pointers in C (2010)

214 点作者 prabhupant超过 6 年前

13 条评论

_kst_超过 6 年前
I checked the section &quot;Interlude: Arrays&quot; because the relationship between pointers and arrays in C is a major sticking point.<p>It claims that, given a declaration<p><pre><code> int array[] = { 45, 67, 89 }; </code></pre> the expressions &quot;array&quot;, &quot;&amp;array&quot;, and &quot;&amp;array[0]&quot; are all equivalent. They are not. &quot;&amp;array&quot; and &quot;&amp;array[0]&quot; both refer to the same memory location, but they&#x27;re of different types.<p>In the next section:<p>&quot;By the way, though sizeof(void) is illegal, void pointers are incremented or decremented by 1 byte.&quot;<p>Arithmetic on void pointers is a gcc-specific extension (also supported by some other compilers). It&#x27;s a constraint violation in standard C.<p>I don&#x27;t think this is the &quot;best&quot; article on pointers in C.<p>I usually recommend section 6 of the comp.lang.c FAQ, <a href="http:&#x2F;&#x2F;www.c-faq.com&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.c-faq.com&#x2F;</a>
评论 #18587332 未加载
评论 #18587241 未加载
评论 #18591191 未加载
评论 #18586727 未加载
评论 #18588420 未加载
macintux超过 6 年前
I don’t have my copy at hand, but <i>Expert C Programming: Deep C Secrets</i> has the best coverage of pointers and arrays I’ve seen.<p>In particular, it supplies a useful algorithm for decoding all pointer declarations such as functions that return function pointers.<p><a href="https:&#x2F;&#x2F;www.goodreads.com&#x2F;book&#x2F;show&#x2F;198207" rel="nofollow">https:&#x2F;&#x2F;www.goodreads.com&#x2F;book&#x2F;show&#x2F;198207</a>
评论 #18586575 未加载
aasasd超过 6 年前
Ah, boxes again.<p>For me, all confusion about C&#x27;s pointer-happiness cleared up when I finally realized that C (and Asm, I guess) works with heap memory as a big blob of bytes, and it&#x27;s programmer&#x27;s job to keep the blob&#x27;s contents from getting messed up―with some thinly-veiled help from the language and the compiler. Everything else, including variables, is just syntactic sugar when it points to the heap.<p>(With the clarification that afaik variables are different when they&#x27;re on the stack or registers, becoming first-class &#x27;indivisible&#x27; entities).
评论 #18587090 未加载
评论 #18586789 未加载
评论 #18589931 未加载
评论 #18587081 未加载
评论 #18588819 未加载
kccqzy超过 6 年前
The title claims everything, but certainly it doesn&#x27;t cover everything. It mentions const but doesn&#x27;t mention volatile. It also doesn&#x27;t mention restrict which is more confusing than const&#x2F;volatile. It didn&#x27;t mention the strict aliasing rule. It actually didn&#x27;t even mention NULL.
评论 #18587411 未加载
User23超过 6 年前
No C pedantry thread would be complete without a link to one of the finest resources on the subject: <a href="https:&#x2F;&#x2F;blog.regehr.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blog.regehr.org&#x2F;</a>
Apocryphon超过 6 年前
I&#x27;ve always been partial to Dennis Kubes&#x27; five minute guide:<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=4389691" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=4389691</a>
maxxxxx超过 6 年前
I always wonder what makes pointers so difficult for some. So far I have always been able to explain it to people by drawing a linear memory space and then showing how different types are allocated. It seems to me that pointers are one the easier concepts in programming.
评论 #18586422 未加载
评论 #18586701 未加载
评论 #18586895 未加载
评论 #18586931 未加载
评论 #18586952 未加载
评论 #18587086 未加载
评论 #18587434 未加载
评论 #18590932 未加载
评论 #18587101 未加载
edoo超过 6 年前
Pointers in C are an incredibly simple concept. So simple it might take you years to master them.
ktpsns超过 6 年前
When graphical gimmics steal the show: <a href="https:&#x2F;&#x2F;boredzo.org&#x2F;pointers&#x2F;boxes.png" rel="nofollow">https:&#x2F;&#x2F;boredzo.org&#x2F;pointers&#x2F;boxes.png</a> visualizes both pointers and their target (an integer) as 3d boxes. So the sizeof(int) is the edge length of this target?<p>Normally we see such guiding images with 2d boxes. There&#x27;s nothing wrong with 3d because clearly, integers are also not 2d (they are not even 1d). However, don&#x27;t associate the size of theses boxes with the memory size of an element. This overstresses the analogy and suggests the whole thing is a vector space, but it isn&#x27;t.
ananonymoususer超过 6 年前
Some of the cited examples are missing underscores. E.g. &quot;<i>ptr a&quot; should be &quot;</i>ptr_a&quot;.
mchobbes超过 6 年前
This is why people think programming is difficult. That same article could have been written in a significantly less convoluted way, and had a much broader reach, particularly for people who aren&#x27;t already at least moderately familiar with C.
em3rgent0rdr超过 6 年前
&quot;Everything you need to know about pointers in C&quot;<p><i>everything</i>?
评论 #18587415 未加载
keyle超过 6 年前
I joked the other day to a co-worker, currently working full time in Python, that you get used to the list comprehension and other nice things of Python so much, that you&#x27;ll never be able to go back to gnarlier languages like Java&#x2F;C. It&#x27;s just too nice. You can get python to run really fast nowadays and if you can&#x27;t, you still got nim.
评论 #18587077 未加载
评论 #18586923 未加载