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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Modern C [pdf]

392 点作者 brakmic超过 8 年前

35 条评论

jackhack超过 8 年前
I wish I could like this book, but after reviewing the first chapter I can only imagine the confusion of students. I support very much the idea of breaking the book into levels, but it attempts to cover far too much, far too quickly and I don&#x27;t believe this book would be useful for those who are not already familiar with the language.<p>I&#x27;ve been writing C since the late 1980s, moved to mostly C++ by the mid 90s, C# in the 2000s, and now I&#x27;ve come back to C. Most recently built some realtime components and drivers, having to drop back to C77. I mention this as I&#x27;ve taught many colleagues along the way and I&#x27;m sensitive to the places where beginners tend to get hung up with problems and I&#x27;ve come to anticipate many of the questions along the way. Let me take a moment to illustrate the base of the problems i see:<p>&quot;Too much, too fast.&quot; The best example is right on page 2: a program which demonstrates a complex printf format string, along with arrays and loops. I can&#x27;t help but sarcastically ask &quot;Are you sure that is how you want to introduce someone to the language?&quot; A beginner&#x27;s eyes will glaze over.<p>Seriously, the way to introduce the language is simple examples. Explain the main is the entry point where all programs begin running, and that main returns it&#x27;s success or failure to the operating system (or other program that called it). 3 lines of code.<p>Then add a SIMPLE print, if you wish, or a variable declaration. Int. Float. char. again, it MUST be simple. Introduce loops. Then show how to move some functionality out of main into a subroutine&#x2F;a new method&#x2F;new function, how to call that function, and return results. Talk about header files, etc.<p>From there, dive into the rest of the base language... talk up arrays, memory management, heap&#x2F;stack, pointers, libraries, exceptions, etc.<p>But this is only my experience, and I&#x27;m sure that it is different for others. Kind regards.
评论 #13056660 未加载
评论 #13056430 未加载
评论 #13057001 未加载
colanderman超过 8 年前
While I like a lot of what&#x27;s in here,<p><pre><code> for (size_t i = 9; i &lt;= 9; --i) </code></pre> is a pretty terrible example to put in the second chapter. I would not let that line pass code review. There is no need or place for cutesy cleverness in C.<p>EDIT: Ugh, just found this too:<p><pre><code> isset[!!largeA[i]] += 1; </code></pre> Not only is that confusingly cutesy, but <i>largeA[i] is a double</i>. Please DON&#x27;T write – or encourage beginners to write! – such smug code!<p>EDIT2: In section 5 is the statement than unsigned integers &quot;can be optimized best.&quot; This is flatly untrue on x86 and I suspect many other architectures. Compilers can and do take advantage of undefined signed overflow to optimize signed arithmetic; the same is not possible with unsigned arithmetic. See <a href="https:&#x2F;&#x2F;kristerw.blogspot.com&#x2F;2016&#x2F;02&#x2F;how-undefined-signed-overflow-enables.html" rel="nofollow">https:&#x2F;&#x2F;kristerw.blogspot.com&#x2F;2016&#x2F;02&#x2F;how-undefined-signed-o...</a>
评论 #13056290 未加载
评论 #13056182 未加载
评论 #13056265 未加载
评论 #13056250 未加载
pawadu超过 8 年前
The author has also been involved in development of &quot;musl&quot;, a modern C11 compliant standard library implementation:<p><a href="http:&#x2F;&#x2F;www.musl-libc.org" rel="nofollow">http:&#x2F;&#x2F;www.musl-libc.org</a><p><a href="https:&#x2F;&#x2F;gustedt.wordpress.com&#x2F;2014&#x2F;10&#x2F;14&#x2F;musl-1-1-5-with-full-c11-library-support&#x2F;" rel="nofollow">https:&#x2F;&#x2F;gustedt.wordpress.com&#x2F;2014&#x2F;10&#x2F;14&#x2F;musl-1-1-5-with-ful...</a>
评论 #13055347 未加载
评论 #13056247 未加载
SwellJoe超过 8 年前
It&#x27;s been a decade or more since I&#x27;ve worked in C (and have never been a heavy C coder). Is &quot;modern C&quot; really a thing?<p>I mean, is there some subset of C that is safer than what I think of when I think of C? I know about stuff like reference counting techniques, rather than manual memory management, for example, and that goes miles towards safer coding. But, even so, the variety of ways you can shoot yourself in the foot with C are seemingly beyond counting. Are threads and async easier and&#x2F;or safer now than 10-20 years ago, and with more direct language or standard library support? Is memory management in the standard library safer today? Are there concurrency primitives (beyond low-level interacting with epoll or kqueues or even fork or whatever)?<p>I mean, it&#x27;s obviously <i>possible</i> to write reliable, safe, secure, software in C (Linux, Git, SQLite, all come to mind), but how much easier has it gotten? Would anyone choose C for a new systems project with no legacy baggage or dependencies, in a world with Rust and Go?
评论 #13054871 未加载
评论 #13053143 未加载
评论 #13052997 未加载
评论 #13053290 未加载
评论 #13053063 未加载
评论 #13055010 未加载
chrisd1100超过 8 年前
I&#x27;m really surprised by the &quot;hate&quot; for C that is appearing in these comments. What ever happened to actually enjoying the danger of getting low level? Is assembly also useless because it isn&#x27;t readable?<p>There is a lot of great code written in C, and a lot of crappy code written in C. Because C doesn&#x27;t protect you from yourself, it exacerbates any design flaws your code may have, and makes logical errors ever more insidious. So in this sense, the quality of the C you write is really a reflection of you as a C programmer, not the shortcomings of the language. Maybe you&#x27;ve been badly burned by C in the past, but keep an open mind and understand that C can be beautiful.
评论 #13056822 未加载
评论 #13055636 未加载
评论 #13055675 未加载
评论 #13056137 未加载
评论 #13056149 未加载
评论 #13056323 未加载
评论 #13055813 未加载
评论 #13055680 未加载
评论 #13056414 未加载
评论 #13060060 未加载
评论 #13057400 未加载
评论 #13056519 未加载
marmaduke超过 8 年前
It&#x27;s nice to see this perspective kept alive. I put some effort into a numerical library (github.com&#x2F;maedoc&#x2F;sddekit) in C99, and I didn&#x27;t find the language lacking until I tried to imitate inherited interfaces with virtual dispatch by hand (empirically I can say, a poor move in C lib design).<p>I did find it useful to apply rules like only use uint32_t, double &amp; bool as primitives.<p>My main wish is that it would be possible to opt into automatic const &amp; restrict, as a compiler flag or pragma, so that something like<p><a href="https:&#x2F;&#x2F;github.com&#x2F;maedoc&#x2F;sddekit&#x2F;blob&#x2F;master&#x2F;doc&#x2F;C.md#aliasing-and-mutation" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;maedoc&#x2F;sddekit&#x2F;blob&#x2F;master&#x2F;doc&#x2F;C.md#alias...</a><p>would be easier to do.
评论 #13055643 未加载
ape4超过 8 年前
Goto is considered useful by the book:<p>The use of goto and similar jumps in programming languages has been subject to intensive debate, starting from an article by Dijkstra [1968]. Still today you will find people that seriously object code as it is given here, but let us try to be pragmatic about that: code with or without goto can be ugly and hard to follow.
评论 #13055919 未加载
评论 #13055904 未加载
评论 #13055924 未加载
评论 #13056120 未加载
评论 #13057593 未加载
AlexeyBrin超过 8 年前
The author provides the book as a free to download pdf at <a href="http:&#x2F;&#x2F;icube-icps.unistra.fr&#x2F;img_auth.php&#x2F;d&#x2F;db&#x2F;ModernC.pdf" rel="nofollow">http:&#x2F;&#x2F;icube-icps.unistra.fr&#x2F;img_auth.php&#x2F;d&#x2F;db&#x2F;ModernC.pdf</a>
zunzun超过 8 年前
I personally prefer Prehistoric C, which only has the two language keywords &quot;ugh&quot; and &quot;grunt&quot;. Modern C has too many keywords for my taste.
评论 #13055265 未加载
评论 #13055674 未加载
评论 #13055531 未加载
nabla9超过 8 年前
What alternatives there are for C&#x2F;C++ if you want to write library that you can call from Python, R, Matlab, Java, Rust, Lua, node.js ... and have good performance?<p>Old ones like Ada and Fortran of course.<p>There are newcomers like Rust and Go. Are their C api&#x27;s mature and portable?
评论 #13055494 未加载
评论 #13055387 未加载
评论 #13055270 未加载
评论 #13055358 未加载
pcr0超过 8 年前
For someone who studied basic C&#x2F;C++ in university and is interested in hacking around in C, should I read this over K&amp;R?
评论 #13055563 未加载
plg超过 8 年前
<a href="https:&#x2F;&#x2F;pragprog.com&#x2F;magazines&#x2F;2011-03&#x2F;punk-rock-languages" rel="nofollow">https:&#x2F;&#x2F;pragprog.com&#x2F;magazines&#x2F;2011-03&#x2F;punk-rock-languages</a>
Waterluvian超过 8 年前
I&#x27;ve had no luck learning a language on its own. But I&#x27;ve had a lot of luck learning languages as part of something bigger. Like C# via. Unity, Swift via. 2D game dev in XCode.<p>Any suggestions on what I should apply C to as a way to learn it?
评论 #13055126 未加载
评论 #13054119 未加载
评论 #13053228 未加载
评论 #13053222 未加载
kruhft超过 8 年前
The best book I had for learning more about C was titled &#x27;Writing Bug Free Code For Windows&#x27; from the late &#x27;90s early 2000&#x27;s. It contained a complete object oriented system using simple header tricks and data hiding plus covered all sorts of pre-processor tricks that aren&#x27;t evident until you really dig into what C can really do. I&#x27;m sure it&#x27;s impossible to find now, but recommended.
评论 #13059883 未加载
minxomat超过 8 年前
I get a 500 error. Here&#x27;s an archive link: <a href="http:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20161128093244&#x2F;http:&#x2F;&#x2F;icube-icps.unistra.fr&#x2F;img_auth.php&#x2F;d&#x2F;db&#x2F;ModernC.pdf" rel="nofollow">http:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20161128093244&#x2F;http:&#x2F;&#x2F;icube-icps....</a>
qwertyuiop924超过 8 年前
Can any C programmers evaluate this book? I don&#x27;t do a lot of C, so I can&#x27;t really do it.<p>Does it advocate good best practices?<p>Does it talk about pitfalls?<p>Does it overemphasize new, possibly less widely implemented, features?<p>Does it do&#x2F;not do anything else we should know about?
评论 #13053258 未加载
frag超过 8 年前
I want to cry... remembering the old good time of C programming... ohhhh
awinter-py超过 8 年前
Yikes. important words that don&#x27;t appear in this: &#x27;static analysis&#x27;, &#x27;verification&#x27;.<p>On the &#x27;wow&#x27; side, had no idea there was a _Generic macro. Pretty cool.
pksadiq超过 8 年前
I would recommend that anyone who hires a programmer should test his&#x2F;her knowledge in C (especially in areas like code that produces undefined or unspecified results), even if the candidate is never going to code in C, ever.<p>If he&#x2F;she knows these concepts well, that means he&#x2F;she have invested much time, and probably know other things well enough (or can learn them easily).
评论 #13055909 未加载
评论 #13056743 未加载
评论 #13055913 未加载
joveian超过 8 年前
I haven&#x27;t looked at this updated version (site is busy :&#x2F;) but the version I looked at a while ago is quite good.<p>The author&#x27;s use of register to avoid aliasing is something I hadn&#x27;t heard before and seems like a good idea in some cases.<p>Beyond the learning C aspects, I really hope that some of the author&#x27;s suggestions for language extensions are implemented.
giis超过 8 年前
I looked into the table of contents &amp; jumped into pages of it. It looks like good material on best practices &amp; optimization rules &amp; tips. Quickly, bookmarked it &amp; definitely worth reading.<p>IMO, the title here is misleading, I don&#x27;t think new feature is added to C to make it modern.
评论 #13052800 未加载
评论 #13052812 未加载
sndean超过 8 年前
Pardon my noobness, but if I learned and became proficient in C and knew nothing else, would I have a marketable skill?<p>Is it possible for C to be a standalone skill, where ones job could be 100% programming in C, or do you need a lot of auxiliary knowledge outside of that?
评论 #13064597 未加载
评论 #13059314 未加载
评论 #13059450 未加载
评论 #13057265 未加载
leighflix超过 8 年前
Would any C-lovers recommend this book to people that already know programming (but not sys programming) wanting to learn C?<p>I personally know Java, (lil bit) Elixir, and Python.<p>EDIT: I&#x27;ll also be reading K&amp;R along side it.
pawadu超过 8 年前
Any idea if it will be available as a physical book?
manish_gill超过 8 年前
If people aren&#x27;t so into this book, can anyone suggest some other book beyond K&amp;R?
评论 #13058706 未加载
MrRobotic超过 8 年前
I didn&#x27;t use C much. What kind of features of are in the book that make it modern?
评论 #13052886 未加载
评论 #13053388 未加载
hitlin37超过 8 年前
Hi, is there a epub version of this book? The pdf format is painful to read.
评论 #13067216 未加载
kzrdude超过 8 年前
Will this book be printed? I would love to get a paper copy.
maqbool超过 8 年前
where i can find Errata list of this book.
aleksei超过 8 年前
Another day for the HN crowd to express their distaste for C :)
评论 #13055183 未加载
评论 #13055484 未加载
评论 #13056199 未加载
评论 #13055333 未加载
评论 #13055943 未加载
评论 #13055782 未加载
评论 #13055178 未加载
fb03超过 8 年前
ITT: Heated arguments and zealotry. In resume: &quot;C is outdated, its ubiquitousness is just a historical accident&quot;<p>&quot;Better tools exist to do this job&quot;<p>&quot;C is not needed anymore&quot; (Yet no contender has ever come close to it, hehehe --my2c)<p>There, saved you a ton of reading time.
评论 #13056174 未加载
timthorn超过 8 年前
Discussion at: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=13052486" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=13052486</a>
评论 #13056342 未加载
grabcocque超过 8 年前
I mean, the problem cut C is not that it is old, but that it is dangerous.
评论 #13055517 未加载
grabcocque超过 8 年前
It strikes me as odd you&#x27;d even go to the lengths of producing such a book. If you really wanted to protect people from the worst vagaries C the book should simply say &quot;don&#x27;t&quot;.
评论 #13055379 未加载
grabcocque超过 8 年前
Sounds like an Oxymoron. &quot;Make sure your buffer flow exploits are up to the minute! Make sure your systematic lack of memory safety totally captures the zeitgeist!&quot;