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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Hacktical C: practical hacker's guide to the C programming language

218 点作者 signa11大约 1 个月前

13 条评论

siev28 天前
I like the sentiment, I love C. But this book seems riddled with errors and baffling decisions.<p>First of all, the fixed points are LITERALLY NOT FIXED POINTS. They&#x27;re decimal floats. Fixed points are <i>just</i> integers that re-scale when multiplied or divided. There is no exponent field, no nothing. The author seems to have confused the notion &quot;fixed points allow for precise calculations of monetary values&quot; to mean that they&#x27;re decimal. They&#x27;re not. That section of the book contradicts itself constantly and also the code is wrong.<p>Also an ordered vector is used to implement a map&#x2F;set. Because:<p>&gt; Most people would likely instinctively reach for hash tables, and typically spend the next few months researching optimal hash algorithms and table designs.<p>&gt; A binary searched vector is as simple as it gets and performs pretty well while being more predictable.<p>A basic hash table or hash set[1] is both simpler and faster than this solution. And I don&#x27;t see what&#x27;s stopping someone from spending the next few months researching optimal dynamic array growth and searching algorithms instead. This line of reasoning just doesn&#x27;t make any sense.<p>And &quot;Once nice advantage is that since they don&#x27;t need any infrastructure, they&#x27;re comparably cheap to create.&quot; What? It needs a dynamic array!<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;skeeto&#x2F;scratch&#x2F;tree&#x2F;master&#x2F;set32">https:&#x2F;&#x2F;github.com&#x2F;skeeto&#x2F;scratch&#x2F;tree&#x2F;master&#x2F;set32</a>
评论 #43705016 未加载
评论 #43703760 未加载
评论 #43704820 未加载
throwaway789430 天前
<p><pre><code> #define hc_task_yield(task) do { task-&gt;state = __LINE__; return; case __LINE__:; } while (0) </code></pre> That&#x27;s just diabolical. I would not have thought to write &quot;case __LINE__&quot;. In the case of a macro, using __LINE__ twice expands to the same value where the macro is used, even if the macro has newlines. It makes sense, but TIL.
评论 #43681600 未加载
评论 #43681327 未加载
评论 #43681410 未加载
评论 #43684691 未加载
评论 #43681515 未加载
throwaway789430 天前
As someone who has a file with similar hacks, I will say this: I am not a C++ fan, but if you find yourself writing C code where you simulate methods via structs with function pointers often, just use C++ as a basic &quot;C with classes&quot; at that point. You want methods anyway, you have to go through a pointer dereference to call the function, it&#x27;s just not worth the code weirdness. If you have the grit to use structs with function pointers everywhere, you have the grit to stick to the simpler subset of C++.
评论 #43683849 未加载
评论 #43701516 未加载
评论 #43703558 未加载
评论 #43683169 未加载
评论 #43684044 未加载
9d30 天前
&gt; C doesn&#x27;t try to save you from making mistakes. It has very few opinions about your code and happily assumes that you know exactly what you&#x27;re doing. Freedom with responsibility.<p>I love C because it doesn&#x27;t make my life very inconvenient to protect me from stubbing my toe in it. I hate C when I stub my toe in it.
评论 #43684772 未加载
评论 #43683157 未加载
评论 #43682578 未加载
评论 #43683835 未加载
评论 #43683142 未加载
Calwestjobs28 天前
&quot;These days; many programmers will recommend choosing a stricter language, regardless of the problem being solved. Most of those programmers wouldn&#x27;t trust themselves with the kind of freedom C offers, many haven&#x27;t even bothered to learn the language properly.&quot;<p>Same thing people said about other people not compiling by hand lol.
评论 #43703388 未加载
pjmlp30 天前
&gt; The reason I believe C is and always will be important is that it stands in a class of its own as a mostly portable assembler language, offering similar levels of freedom.<p>When your computer is a PDP-11, otherwise it is a high level systems language like any other.
评论 #43682173 未加载
评论 #43682554 未加载
评论 #43683332 未加载
评论 #43682928 未加载
评论 #43683914 未加载
评论 #43701871 未加载
评论 #43682246 未加载
lou130630 天前
&gt; Using a stricter language helps with reducing some classes of bugs, at the cost of reduced flexibility in expressing a solution and increased effort creating the software.<p>First of all, those languages do not &quot;help&quot; &quot;reducing&quot; some classes of bugs. They often entirely remove them.<p>Then, even assuming that any safe language with unsafe regions (Rust, C#, etc) would not give you comparable flexibility at a fraction of the risk... if your flexible, effortless solution contains entire classes of bugs, then there is no point in comparing &quot;effort&quot;. You should at least take into account the effort in providing a software with a high confidence that those bugs are not there.
评论 #43681160 未加载
评论 #43684056 未加载
评论 #43681118 未加载
teo_zero28 天前
Beware that the second section about fixed-point arithmetic is actually about floating point with exponent in base 10.<p>Besides, the operations are all wrong and only work for trivial values of the exponents, like 0, 1 and 2.
nesarkvechnep27 天前
Unpopular opinion but the BSDs are better OS for learning and hacking C. Super stable, amazing documentation, predictable, nice libraries included.
talles30 天前
Any quick way to make a PDF out of this?
评论 #43683005 未加载
akdev1l30 天前
&gt; Microsoft has unfortunately chosen to neglect C for a long time, its compilers dragging far behind the rest of the pack.<p>Is this still true? MSVC is pretty good at compiling C++ nowadays
评论 #43681159 未加载
评论 #43681236 未加载
评论 #43680812 未加载
评论 #43680819 未加载
评论 #43681047 未加载
评论 #43680811 未加载
steinuil30 天前
Some points about the introduction, but otherwise this seems like an interesting collection of (slightly deranged?) patterns in C.<p><i>&gt; The truth is that any reasonably complicated software system created by humans will have bugs, regardless of what technology was used to create it.</i><p>&quot;Drivers wearing seatbelts still die in car accidents and in some cases seatbelts prevent drivers from getting out of the wreckage so we&#x27;re better off without them.&quot; This is cope.<p><i>&gt; Using a stricter language helps with reducing some classes of bugs, at the cost of reduced flexibility in expressing a solution and increased effort creating the software.</i><p>...and a much smaller effort debugging the software. A logic error is much easier to reason about than memory corruption or race condition on shared memory. The time you spend designing your system and handling the errors upfront pays dividends later when you get the inevitable errors.<p>I&#x27;m not saying that all software should be rewritten in memory-safe languages, but I&#x27;d rather those who choose to use the only language where this kind of errors regularly happens be honest about it.
评论 #43684184 未加载
_false30 天前
Honest q: after skimming through the book it&#x27;s unclear how it&#x27;s targeted towards hackers (c.f. academics)?
评论 #43684025 未加载