Throw out your old ideas about C and get to know a programming language that’s substantially outgrown its origins. With this revised edition of 21st Century C , you’ll discover up-to-date techniques missing from other C tutorials, whether you’re new to the language or just getting reacquainted. C isn’t just the foundation of modern programming languages; it is a modern language, ideal for writing efficient, state-of-the-art applications. Get past idioms that made sense on mainframes and learn the tools you need to work with this evolved and aggressively simple language. No matter what programming language you currently favor, you’ll quickly see that 21st century C rocks .
All engineering students take a one semester course fairly early in their education. My experience as a professor is that most of them promptly forget it and never make use of it again. I get alternately amused and discouraged at the lengths some of the students I work with go to avoid programming again. Because that one semester course teaches a programming language, but does not teach someone how to program. This book is meant to take someone through that step. It is sometimes hard to follow (my heavy programming in C was years ago) but it gets someone to where they can be productive.
When someone is referred to me an claims to have some programming background, I have learned to ask a simple question: have you programmed with libraries? I usually get a blank stare, and I know that this person may have taken a class, but cannot do anything useful. What this is how to make programming in C useful. So it builds in working with the various utilities that make C programming useful (I learned pkg-config and profiling with valgrind with this book. And before I used to be able to edit Makefiles but I would not try to write one from scratch) And, of course, working with C using some fairly useful libraries (if I am programming I am general pulling data from databases and using numerical methods, so I am rather pleased at the use of SQLite and GSL as example libraries).
The various tools are very useful. Programming without learning to use the various utilities such as debuggers, library managers, packaging, etc. is an exercise in frustration (and is how the standard introduction to programming course is set up).
Am I a convert? I still regard Python and R as my preferred environments, and I'm not swayed by his arguments that C is a "punk" language. I still find that all the little cruft such as pointers and their management something I'm glad to avoid. But I also regard one of the best features of Python and R the fact that I can dive into C when I need something fast and efficient. So being able to do this more effectively is good to improve my toolkit.
The book is not really for pure beginners. If you did not already have some background in C, you need to get that somewhere else. I got in trouble with some of the examples, so it helped that I have used many of these tools before (even if not all that effectively). It also is opinionated, presenting one way to do things. (of course, that is very useful to someone starting out, knowing one good way is better than having a dozen options in front of you when you don't know what is what). But it can be very good for someone who needs to go from "I have learned C" to "I know how to effectively use C."
Note: I received a free electronic copy of this book from the O'Reilly Bloggers program.
I liked the book's premise, and it has some interesting snippets and gems, but unfortunately it falls short in a couple of areas.
Having information and examples on the surrounding tooling is certainly practical, but the git chapter felt really unnecessary. Git is so ubiquitous nowadays, that I hardly see the point. Including the other tools, however, makes more sense (valgrind, doxygen, make, autotools, etc.). Instead of Git, the author could have played with some of the available static analysis tools, or linters.
A lot of the code samples aren't properly formatted, which is a shame because it gives the impression of carelessness. The book is expected to be an advanced or at least intermediate C book, and as such it doesn't waste much time with the basics. That is all the more reason for the code to have a consistent style throughout. People read it to learn from it, and being inconsistent just sets a bad example. All the author needed was to run a formatter (e.g. clang-tidy) on the code samples.
It also uses the anti-idiom of doing:
int *i = malloc(sizeof(int));
instead of:
int *i = malloc(sizeof(*i));
This is an old idiom, recommended in books and by the SEI CERT C Coding Standard [1].
All in all, reading it was worth it, but the book could be improved for a third edition by fixing the aforementioned issues, and expanding on some of the 21st Century C wisdom, such as that available in the SEI CERT C Coding Standard, or Jens Gustedt's Modern C.
This book is awesome. The author is experienced, clear and funny. Klemens' tactic is to give a crash course in the various tools needed to produce usable, portable, up-to-date C code without getting into boring minutiae that can be googled when needed. To me this book means the difference between being able to compile an executable and being able to write software. I'm actually excited to write some C after this, but also a little scared.
Word of warning: at least a little knowledge of C is required. I did a little C in college back in '98 and I was able to pick most of this up without too much trouble.
On the good side, it will not waste your time with another bottom-up C tutorial. It assumes you know the language enough and throws you into more interesting stuff – various tools and stylistics that you might not have learned if you have studied C "academically".
On the bad side, it just does not go into enough depth. For example, it talks a bit about Make and Autotools, but barely scratches the surface and doesn't go into alternatives (like CMake). There is a lot of accompanying source code (hosted in a really weird place), but every time I decided to play with it, it was disappointing. It throws some ludicrous statements out there (akin to "it's OK to leak a few bytes here and there on a modern machine, as long as it's overall not too much") and the code is sloppy in places (e.g. not free-ing memory in some error paths). The style tries to be cute; keyword "tries". It also wastes a full chapter on git, like anybody needs yet another git tutorial.
If you feel like "some casual C reading", it might be an OK book. But don't expect a lot.
The idea of this book is that the C programming language has been quietly evolving, while C++ and Java took all the glory. But those languages are a mess, C++ in its syntax and gotchas and Java in its resource abuse. In its recent standards and libraries, C has many of the same features, rendering the newer languages mere syntactic sugar. C doesn't candy coat. Or, as this book puts it, it's the "punk rock of programming languages." Fast, messy, and dangerous.
I thought it was an interesting idea, worth hearing him out. It did give some good tips, and helped re-awaken my understanding of C, which has been atrophying in my mind for decades. Most notably, it helped me understand C idioms that have evolved over time, which I know is just as important is knowing the syntax, if you want to have any hope for quickly understanding code other people write. However, this book also reminded me why I hate this language. It fights you every step of the way, turning even simple tasks into an ordeal. It encourages a heavy use of pointers, which turns the code into a sea of asterisks. The book is pretty straightforward to read, but it does have a bad habit of dumping pages of code, with little explanation. I guess the author figures a book on C should reflect the attitude of the language itself.
I'm resolved to the reality that C is the basis for most software and programming, and that isn't changing anytime soon, if ever. It's simply the only realistic option if you want to write low-level code. No matter how advanced the hardware gets, there will always be a need for speed and control, so there will always be a need for C. Might as well get more comfortable with the language, which means updating our understanding of it.
UPDATE: I first read this a couple years ago, and I just finished reading it again. Since the first reading, I've been through a huge undertaking of discovery and learning about programming languages. There were over 20 language I've explored. It's been a lot of fun, and those languages have a lot to offer, but you want to hear something funny? I just kept going back to C. Each time I did, I had a deeper understanding of it. C was the first language I'd written any serious code in, so it felt like coming home. I craved the control it gave me. It feels like talking to the computer directly, rather than having a translator. 15 years after rejecting this language, I'm coming back to it. In these modern times of Ruby, Python, Scala, Haskell, Rust, C++, D, Go, blah blah blah, this book showed me how to modernize C, and get some of the features I crave from it. C is still not pretty, and it can be a bit tedious, but it's FAST, it's simple, and I'm always in the driver's seat. This book deserves the credit for this reawakening, so I'm upping my rating to 5-stars.
This book is filled with tips on how to use non-intuitive build tools and pick up some very bad coding habits while you're at it. I suppose it could be useful as a reference if you really need to know the intricate details of makefiles for some project.
In aggregate, this is kind of a mixed bag, and I wouldn't recommend it to anyone who hasn't spent at least some time learning C the old fashioned way, but for anyone who has, there's a lot of really interesting tips that don't get covered in traditional sources, such as things that made sense to do in the early 80s that are mostly irrelevant on modern machines. The easygoing style is very much appreciated, and I think really sets it apart from most technical works of this nature in making it easy to read. The underlying theme is that "C is punk rock", which is laid out in the introduction, and continued with relevant punk rock song lyrics in the chapter openings and advice that runs counter to the mainstream.
As for downsides, one is that some tips are platform-specific or not considered "best practices", though to be fair they are always marked as such with a caveat. Second, the author has a serious axe to grind with "bloggers", who are often mentioned as being extremely pedantic and frowning at the sort of advice presented in the book. I'm somewhat aware of the culture the author is pushing back against, but the barbs seem a little too pointed and directed at specific (though unnamed) authors for an otherwise professional work. Third, the first couple of chapters are really painful (compiling and the endless series of flags necessary to do so, testing, debugging, packaging...), and the fun stuff really starts in Part II. I understand the necessity of these things, but I can't bring myself to finish any of them quite yet, and I ended up skipping ahead to the parts about the language itself.
This came out sounding more negative than I'd intended, but ultimately, warts aside, this book is very helpful and I'd recommend it to anyone hoping to better understand modern C programming.
If you want to learn to program in C, the time-honoured recommendation is Kernighan & Richie's venerable and succinct text "The C Programming Language". Like the language itself, that book is now getting a bit long in the tooth, and fails to cover the more recent revisions to the language (C99 and C11), not to mention the evolution in operating systems and development environments.
"21st Century C" steps in to fill this decades-long gap and provides an up-to-date perspective on programming in the C language that would make sense to someone stepping out of a time machine from the earliest days of ANSI C89. Having started working through the first few chapters of K&R, I have found this book to be an ideal accompaniment.
The first five chapters provide an overview of the ecosystem of tools that exist to make life bearable for the modern programmer: the command line, package managers, debuggers (gdb, valgrind), version control and so on. This is the kind of stuff that is absorbed by osmosis and quickly becomes second nature to any self-respecting developer; for a dilettante like me, on the other hand, it's very useful to have it all described in one place.
The remainder of the book (Chapters 6 to 13) discusses various aspects of the language and programming style. I have yet to read to this part of the book but at a first glance looks like it will be well worth revisiting, probably when I finish reading Kernighan & Richie.
This was bad. There was nothing new for me in there, except probably asprintf() (and with a title like this I expected a lot more), and all the stuff explained was brief, non-systematic and mostly an explanation of the author's mode of work. Everyone would be better by reading the unix network programming books by Stevens, and a few manuals for whatever he/she sees used in any medium-sized project.
Lots of interesting info, but some really bad advice for anyone who is building production quality applications. If you're an oldschool(ish) c coder, this will introduce you to a lot of the new features of modern c.
Lots of very good information that it took me years working professionally to figure out. Source control, libtool, automake, doxygen, this book covers them all.
Half of this book is an enjoyable up-to-date primer on the C programming language. The other half covers 3rd party libraries and tools which are needed to plug gaps in C's built-in capabilities, undermining the author's claim that C is still viable as a development platform. I haven't coded much in C for decades, having moved on to full-featured platforms built around other languages . As a relatively easy-to-read refresher on C, the book works well. As an argument in favor of using C for general purpose programming today, it fell short for me.
After a couple years or three I have to revise my evaluation of this book up to five stars, from four--because I keep coming back to it.
If you are writing in C today, you should read this book. Argue with it. Learn from it. The language did not halt in its tracks because K&R stopped updating The C Programming Language. You know that--Klemens's 21st Century C is here to ensure that this knowledge comes across in the code you actually write.
From his tone, his many code examples, and his concern with practical problem domains, I infer that Klemens is an expert practitioner. He has made a survey of all the introductory C programming books you are likely to have encountered (or had assigned to you as a student), and written two entire sections of this book explaining the ways in which those books sometimes wasted your time, and what they left out that you really should be aware of.
Many of the omissions in the existing literature that Klemens is on a mission to rectify seem to be driven by inertia; having written a C text in the 1990s, it's easy for an author and a publisher to agree that only minimal updates reflecting subsequent revisions of the language standard are necessary. Even 20 years after C99, we see people assigning to structs without using designated initializers, a feature that makes it a lot harder to screw up.
Klemens has also read some of the more storied wisdom, like van der Linden's Expert C Programming: Deep C Secrets and Hanson's C Interfaces and Implementations: Techniques for Creating Reusable Software. His bibliography is excellent, well-judged, and could be improved only by annotations. (Since he surveys so many introductory C texts, it would be useful for him to note which ones simply aren't worth bothering with. Myself, I tend to suspect anything with an authorial surname of "Dietel" or "Prata" as having been ghost-written, and probably badly. Do you disagree? Leave me a comment.)
The only other recommendation I would make for a 3rd edition--which this book fully deserves--would be for Klemens to flesh out the sly trick he remarks upon in a footnote on page 240: "Yes, this is a struct holding a single integer. One day, it might save your life." I know what he's doing here, both with the technique (forcing good, strong type-checking) and by passing over it in haste (trying to avoid attacks from the sort of people who cast between pointers and integers on every architecture, never check for error returns without a gun to their head--and then only if it's loaded and they hear the hammer cocking--and think the VAX-11/780 was the pinnacle of computer architecture--if only we could clock it at 4 GHz!).
Klemens is also au fait with the C standards documents, and backs up his claims with citations down to the sub-sub-subsection.
Klemens gives the best presentation of the C preprocessor I've yet seen. cpp usually gets crappy coverage because it is regarded as something of an embarrassment. I think that's a bit unjustified--there are plenty of other design mistakes in C to be embarrassed about, and which writers and programmers happily defend as if they were virtues. You can't escape cpp and it's a useful tool, when used carefully--Klemens shows you how. (Just please don't ever use cpp for anything but preprocessing C. There are a billion macro processing languages out there. Learn a second one.)
With the C preprocessor and with other features, some of which came "late" to C--meaning after 1989, the last version Dennis Ritchie was willing to bless--Klemens shows you how to write for robustness, not cleverness. This is another way I infer that he is seasoned. Code cowboys come and go, usually leaving a barely-working proof of concept in their wake that fails at the slightest environmental perturbation. Engineers build things that last, fail gracefully, and emit diagnostic messages that impart meaningful information.
Because Klemens's 21st Century C is not introductory, it should not be the first book about C that a person reads.
I've read it all and I keep reading parts of this great little book. Probably the best,most helpful book I've read about programming in the C language right after "The C Programming Language," 2nd edition, by Kernighan and Ritchie.
// just a snippet of an imaginary program I didn't write. I think it's correct - I used stuff from the // book to write it. I didn't know about the brackets, f'rinstance.
/* the double slash is a new way of commenting in C, to annotate the program and the other, established way is to bracket the non-C text between a slash, then asterisk, at the start and an asterisk, then a slash at the end. You hit return in between. The '//' method is for one line only */ char **review ={"this variable is in scope but", "after the open bracket, it goes out of scope", "until the close bracket"} { char **review[]={"I learned some really good stuff", "understanding scope is very useful and I learned it in this book", "also the forms of variable and the usage of the terms denoting them, which changes by the context of the program they're declared in is extremely USEFUL and IMPORTANT to know"};
/* also, important and use full information about multithreaded programming, oh, the list goes on and on. I'm using what I've learned a LOT. Learning what tail end recursion is and how it works was like being born again, a whole new beginning. And it sped up my program a bunch, too*/
Tons of great ideas for writing modern, flexible C. In all honesty, I'm not sure if my disappointments with some of the tips regarding makefiles and dependency management have to do with the book or the ecosystem itself. It seems very difficult to set up a C project compared to Python, Ruby, or other languages... luckily, Xcode takes care of a lot of the process, but it would have been nice if the author presented a similarly convenient set of tools. Maybe I'm just being picky.
o trecere în revistă a ceea ce-ți trebuie pentru a programa în C. Nu intră în amănunte dar e bună ca să-ți dea câteva idei de ce ar trebui să cauți mai departe, iar pe alocuri chiar o poți folosi ca pe un "quick guide" (în special partea de source control - git). În plus se concentrează pe "noul C": C99/C11 care are câteva lucruri pe care eu (programator C/C++ de 11 ani) nu le știam (cum ar fi keyword-ul "restrict").
I had much more expectations and expected to find something useful for myself – I did not.
This book, however, would do a good job showing just-after-K&R beginners how to give birth to C code and stay sane. Another thing to be aware of: like most tutorial-type books this one already is outdated and does not overview some of useful tools available today.
An enjoyable read, great to get you pumping for some low-level hacking - now with proper library use and great external interface. I'd recommend it as a second or third C book to read, for me personally there were very few technical things I didn't already know, but a wealth of encouragement to use things I knew about but wasn't sure were worth using in practice.
Apart from a couple of useful tricks that could have been described on ten pages at most, this book is mostly a waste of time. Skim through it, to get a hold on some of the macros and maybe the Glib section, but don't devote too much time on the rest.