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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

A Guide to Undefined Behavior in C and C++ (2010)

41 点作者 peeyek将近 10 年前

3 条评论

tedunangst将近 10 年前
&gt; undefined behavior in C&#x2F;C++ is that it simplifies the compiler’s job, making it possible to generate very efficient code in certain situations.<p>I&#x27;ve been growing more skeptical of this claim over time. First, more evidence would be nice instead of &quot;some loops&quot;. What is a program (not a benchmark) that has an observable performance difference when compiled with and without -fwrap?<p>Second, it seems counter productive. The word is now out that if you use signed ints, the compiler is going to fuck you over. So now everybody is (or should be) using unsigned ints, and whatever optimization the compiler was performing, now it can&#x27;t. A lot of grief for no progress.
评论 #9887149 未加载
评论 #9887482 未加载
jasode将近 10 年前
Fyi... Chris Lattner (LLVM, Apple Inc) wrote some companion articles on the same topic and refers to these John Regehr posts.<p><a href="http:&#x2F;&#x2F;blog.llvm.org&#x2F;2011&#x2F;05&#x2F;what-every-c-programmer-should-know.html" rel="nofollow">http:&#x2F;&#x2F;blog.llvm.org&#x2F;2011&#x2F;05&#x2F;what-every-c-programmer-should-...</a>
jrbrtsn将近 10 年前
Isn&#x27;t complaining that (INT_MAX + 1) is undefined the same as complaining that (8&#x2F;0) is undefined? What meaningful functionality could be gained by defining overflow behavior? If you really want to know what INT_MAX + 1 is, try:<p>printf(&quot;INT_MAX+1= %lld\n&quot;, (long long)INT_MAX + 1LL);
评论 #9888266 未加载
评论 #9889169 未加载