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.

Pointers in C (2010)

214 pointsby prabhupantover 6 years ago

13 comments

_kst_over 6 years ago
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 未加载
macintuxover 6 years ago
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 未加载
aasasdover 6 years ago
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 未加载
kccqzyover 6 years ago
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 未加载
User23over 6 years ago
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>
Apocryphonover 6 years ago
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>
maxxxxxover 6 years ago
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 未加载
edooover 6 years ago
Pointers in C are an incredibly simple concept. So simple it might take you years to master them.
ktpsnsover 6 years ago
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.
ananonymoususerover 6 years ago
Some of the cited examples are missing underscores. E.g. &quot;<i>ptr a&quot; should be &quot;</i>ptr_a&quot;.
mchobbesover 6 years ago
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.
em3rgent0rdrover 6 years ago
&quot;Everything you need to know about pointers in C&quot;<p><i>everything</i>?
评论 #18587415 未加载
keyleover 6 years ago
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 未加载