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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Understanding effective type Aliasing in C [pdf]

53 点作者 quelsolaar10 天前

4 条评论

cancerhacker9 天前
It’s fun to consider how C devolves into assembler. In my mind, C and its derivatives dissolve into 68K assembler as I’m writing or debugging. Thinking about code this way lets me get a feel for how all the bits all fit together.<p>It seems like a lost art to think that way. It’s disturbing to me how many candidates couldn’t write Hello World and compile it from the command line.<p>Everyone should spend some time with godbolt.org or better, the -save-temps compiler flag, to see how changes affect your generated code. Right now. I’ll wait. (Shakes cane at kids)
评论 #43911305 未加载
评论 #43912971 未加载
评论 #43911738 未加载
pansa29 天前
&gt; <i>Any access of memory using a union, where the union includes the effective type of the memory is legal. Consider:</i><p><pre><code> union { int i; float f; } *u; float f = 3.14; u = &amp;f; x = u-&gt;i; </code></pre> &gt; <i>In this case the memory pointed to by “u” has the declared effective type of int, and given that “u” is a union that contains int, the access using the “i” member is legal. It’s noteworthy in this that the “f” member of the union is never used, but only there to satisfy the requirement of having a member with a type compatible with the effective type.</i><p>Is this a typo? Should it say &quot;declared effective type of <i>float</i>&quot; and &quot;“u” is a union that contains <i>float</i>&quot;?<p>It&#x27;s interesting to see type-punning using a union - I&#x27;ve read that it should be avoided and to use `memcpy` instead. Are there any issues with the union approach in C? Or is the advice to prefer `memcpy` specific to C++, where AFAICT the union approach is undefined behaviour?
评论 #43912322 未加载
0xCE07 天前
The writer seems to be Eskil! <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;@eskilsteenberg&#x2F;videos" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;@eskilsteenberg&#x2F;videos</a>
jklowden8 天前
What drugs were they on? Why on earth is there any distinction between variables allocated statically, on the stack, or on the heap? I allocate a struct, copy data to it, and those data have no Effective Type? Because I started with malloc? Give me a break.<p>The point of the type system is to define types. It’s not to make the compiler’s job easier, or to give standards committees clouds to build their castles on. No amount of words will justify this misbegotten misinvention.
评论 #43915944 未加载