The gist of it was that K&R ignores the safety problems in C and there is no discussion of the habits/constructs seasoned C programmers have developed to make sure their code is safe. Of course, many of those habits were developed after K&R, but that's why we need revisions and new sources.
In its place, Zed Shaw (the author), updated Learn C the Hard Way to concentrate on using C safely -- it is an awesome way for a newbie to learn C. Even if you don't agree (and want to use K&R), read this alongside it.
To learn C -- I'd recommend LCTHW.
> Too many factual problems and a presentation that gets you to do things wrongly before being shown how to do it correctly, and not even always then.
Eh?? Isn't that the whole point of "Learn __ the Hard Way"? ie., by making mistakes and learning from them?
The main critique of Zed seems to be that he didn't say it was impossible to protect a C function from the caller. So what? There is a big difference between his suggested style and the style you'd get from an uncritical reading of K&R, even though neither is 100% safe from the caller.
Personally I feel that pretty much any of the typically-cited C books are too heavy for this purpose. What you really want is a Learn C in 21 Days type of book, that will walk you through the build system as well as the basic of the C language. Even that may be too heavy - a well-written online tutorial would probably be a superior solution. Sadly, I haven't needed to look at "Intro to C" material for a very long time, so I can't really comment on what might be appropriate resources available these days.
When reversing it doesn't help you if you know what a single instruction is doing. You need to be able to recompile the program in your head, and translate it back to high-level logic. You need far more knowledge of C than just the 'learn C in 21 days' stuff if you really want to start reverse engineering.
In any case, there was definitely a network that was being used by a lot of people by 1988.
The first commercial ISP in the U.S. was founded in 1989.[1] Until then, only a few people in universities and the tech and defense industries had access to the internet. According to this chart[2], the number of internet hosts in 1992 is barely distinguishable from zero on today's scale.
[1] https://en.wikipedia.org/wiki/Internet_service_provider#Hist...
[2] https://en.wikipedia.org/wiki/File:Number_of_internet_hosts....
As a side note, it is (nearly) impossible for something that hasn't changed in almost 30 years (k&r) to keep up with something as dynamic as a program language. Even if the standard hadn't changed, the way a language is used is practically guaranteed to change over a period that long. Although, as somebody else said, the exercises in k&r are great and it covers a lot of interesting information, but does seem pretty light.
If you have some programming language experience already I'd suggest going with 21st Century C by Ben Klemens. There's a decent refresher on the language in the appendix and most of the book spends time talking about all of the things most text books skip over: tooling, debugging, the environment, useful libraries, etc. It also covers C99/C11 which is where anyone new to C should be starting these days, IMO.
You might also want to pick up Expert C Programming by Peter Van Der Linden. It's also starting to show its age but is useful for a deep, historical dive into why and how C evolved the way it has. It will keep you from yelling, "why on Earth would you ever do it that way!?" when you get a little frustrated with C's quirks. There are reasons most of the time (even if they're not always good ones in retrospect).
Also there's nothing quite like ordering yourself a copy of the specification. It's not insurmountable and easy to chew through a section here and there as you go along.
Happy hacking!
UPDATE: You can wait to purchase a copy of the ISO ANSI C specification as it can be quite expensive... you'll find it on http://webstore.ansi.org/RecordDetail.aspx?sku=ISO%2fIEC+989...
However the exercises in K&R are excellent so make sure you do them all. Actually the cost of K&R is justified just for the exercises IMHO.
Also get Understanding and Using C Pointers by Richard Reese, it is a must have.
Two other books I very much enjoyed are Head First C and 21st Century C (2nd edition). Head First has some nice "extra" bits like threads and networking in C. 21st Century C explains sensible, modern ways to do things in C and, more importantly, things you should NEVER do in C!
Then after that go learn Assembler, or even better, implement a compiler. You'd probably learn a ton of the things you need to know for reverse engineering code from just making one simple compiler.
K&R would be fine for this purpose, I think. As a more general introduction to C, I think it's still great, but really needs to be paired with something more modern if you're planning to actually develop applications in C.
See it here: http://careferencemanual.com/, at its home page.
Or at Amazon here: http://www.amazon.com/Reference-Manual-5th-Edition/dp/013089....
Turn to this book when you have questions. The authors are Harbison and Steele. If you become a C programmer, you will want and need this book. So you may as well get a copy now.
Another (more advanced) book is The C Puzzle Book.
http://www.amazon.com/The-Puzzle-Book-Alan-Feuer/dp/02016046....
It's older and I'm not sure it's totally up-to-date with the latest version of C. But it's still very valuable. If you finish this book, you will be a C ninja, and it isn't too hard.
K&R is outdated, in my opinion, because it is too skimpy.
But it is still a reference book not a get started with C guide.
Additionally, LCTHW let me down significantly (regardless of what you think of the author).
If I could make two recommendations to you, the first would be that reading a text book will never make you good at C programming; like many other languages (or perhaps programming in-general with the exclusion of highly-academic languages), creating your own personal projects and learning as you go with a mentor to guide you is probably the single best way to become proficient.
Second, eventually, you should read the current Spec (or at least, the latest draft and all its TC). Before getting to that, if you are convinced that a text book would be helpful, go look at http://icube-icps.unistra.fr/img_auth.php/d/db/ModernC.pdf
All the best,
I wholeheartedly agree. Not to say they're mutually exclusive, but nothing comes close in terms of education / time density to an experienced programmer telling you what you did wrong and why.
You will be better served by reading a more recent (C99) and carefully considered book such as K.N. King's C Programming: A Modern Approach.
Some of the other people have said things like: "The gist of it was that K&R ignores the safety problems in C and there is no discussion of the habits/constructs seasoned C programmers have developed to make sure their code is safe. Of course, many of those habits were developed after K&R, but that's why we need revisions and new sources."
This is indeed extremely important, but I also think in an introductory book these details will be very overwhelming. Safety in C is a very complicated topic, and indeed entire books have been written about it[1].
I find these "critiques" rather misguided. After all, we all know Newton's laws are an inaccurate picture of reality, but one would hardly start teaching quantum physics straightaway. C is a hard language with a lot of bizarre edge cases, and K&R C does an excellent job of presenting the language without all these pesky details.
The second criticism seems to be that it is outdated. This is true, but you can catch up with coding conventions and best practices very quickly.
To summarize, K&R C is excellent for introducing people to C. I would suggest completely ignoring safety issues et cetera at the start and just have fun solving the exercises!
---
[1] Secure Coding in C and C++ is a really good book on this topic. http://www.amazon.com/Secure-Coding-Robert-C-Seacord/dp/0321...
PS: Since you are interested in reverse engineering, after finishing K&R C I would recommend reading Computer Systems: A Programmer's Perspective.
My personal favorite, because it explains better (so I think) and dives into a little more depth where K&R leaves you to extrapolate on your own, is Peter van der Linden's "Expert C Programming" (Deep C Secrets): http://www.amazon.com/Expert-Programming-Peter-van-Linden/dp... . Also, I enjoy the author's entertaining style, and think it aids learning.
Depending on the age and quality of the code OP is reverse engineering, learning a very modern style of coding might somewhat oppose OPs goal.
I'd advise OP to rephrase the question to something like "I really want to learn how unixv6 works as a retro computing hobby project and I want to know what books the authors of unixv6 originally read to learn C". Or "I want to eventually be able to reverse engineer stereotypical 90s/00s microcontroller code so I want to know what textbooks an average EE used to learn C in that era"
Its like the difference between "Programming Perl" 1st edition manual and 2014 edition of "Modern Perl"
I think it still is a nice book for beginners, but not the most pragmatic option. You may prefer to start with something more up to date. But if you really want to learn C, read it at some point.
As a side note, even if C was already a dead language, I would still recommend to read the book just as an example of good writing.
This is also a good presentation for safer C programs https://www.bsdcan.org/2010/schedule/events/172.en.html
But, at this point in my life, I believe the K&R book is a good read if you are into the history of programming languages or going to write a book about your own language and want to avoid the bloat common in computer books. It is not a great modern C book and has not been updated in years. I wish this wasn't true, but pointing new programmers to that book in anything other than a historical context is just not serving them well.
It is really too outdated and does not cover the language as it is used or safe programming in the language. I'm not sure what the replacement is these days.
You'll get a modern approach to C programming and it had great exercises.
A book I would recommend, particularly if Zed Shaw's Learn the Hard Way does not appeal to you is Head First C.[1] The underlying pedagogy of programmed instruction is similar. The exercises are more diverse, the tone is lighter, and the overall presentation more approachable.
Good luck.
I can't speak to what you need for reverse engineering, so I'll let others say whether it's appropriate for that.
If possible, check the suckless.org projects, they tend to have pretty idiomatic and clean source codes.
"C Interfaces and Implementations" by David R. Hanson http://www.amazon.com/Interfaces-Implementations-Techniques-...
That being said, the example code in the book is sometimes terse at the expense of readability (and security). I would try to pick up a more modern, and defensive, coding style from the web.
But to be honest, if you want to do reverse engineering, I would instead pick up a copy of "80386 Programmer's Manual" from Intel as you'll be living in assembly.
I must ask though and I don't mean this in a challenging way but isn't this teaching ASM for an old cpu? I'm largely ignorant of ASM so feel free to correct me. I just don't see the point of learning asm for that (As I believe that ASM changes from cpu to cpu).
A book I read alongside K&R was "Illustrating C" by Donald G. Alcock, even though it is out of print and quite hard to find I'd recommend hunting a copy down as it explains the concepts visually and for me, it was the only book that made things fall into place.
http://www.amazon.com/Illustrating-C-Ansi-Iso-Version/dp/052...
I ask honestly, why? Other than nostalgia and as a signal to others what does it bring the modern C programmer? I have it on my shelf, but it is part of my history.
As you say yourself, it is part of your history, you've probably forgotten which concepts that K&R taught you and the OP is trying to learn C from scratch.
The OP mentions that they are learning C to help them with their reverse engineering skills, so learning about the older ways that C was programmed is also invaluable as those insecure programming techniques are still (unfortunately) widely used today and if OP wants to exploit such bugs, then all information is useful!
You mention nostalgia, and yes that is certainly one of the reasons as in my opinion the preface, the preface to the second edition and the introduction in the K&R book are worth the cost alone.
Besides, the book is so thin and flexible and makes a perfect ultra-portable, high-definition, long-life, skills acquisition device that works well on bus journeys, flights etc. ;)
I would say owning it is better than not.
This weighed heaviest in my mind. K&R is a poor book to learn modern C. Its like saying a person starting out with Fortran today should learn from a book written for FORTRAN 77. It might be ok later once better habits have set in, but for someone who didn't live through that era, it just seems like a waste of time and money for learning modern C.
I am still convinced its a signal to others and an aspiration for what we want out of language authors, but it just isn't up to date for the task of being the first C book someone reads.
Then, every time I learned something in programming using C (studying operating systems), I read K&R again and found that the answer was there even if I didn't see it before. So it was a good way for me to "validate" that I understood something new.
Note that I never used C at a very high level, and I don't know what is modern C programming, so it may not apply.
If you want to learn C history, it's invaluable. If you want to learn C, it's only the first of many books you'll have to read.
Yeah you'll be able to identify all the parts and in theory what they do, but you won't understand the why of things. There's really no substitute for experience in understanding why something is designed the way it is.