10

C99 has been with us for a while now. It introduces a lot of features that are not in K&Rs The C Programming Language. None of them are particularly radical. However, even small features like being able to intermingle declarations and code change how one organizes code.

While I still consider the K&R book an invaluable reference, and like its writing style, is there a better book that takes into account the C99 standard? I'd buy a third edition of K&R in a heartbeat, but I don't think that is going to happen.

Kusalananda
  • 103
  • 2
Justin Dearing
  • 879
  • 1
  • 7
  • 18
  • There really isn't a C99 updated English version? The Czech translation of this book is updated for C99. – Šimon Tóth Sep 08 '11 at 11:09
  • @Let_Me_Be The 2nd edition of the K&R book was published in 1988. There is no newer English version of the book. That edition covers ANSI C from 1988. – Thomas Owens Sep 08 '11 at 14:09
  • Because of how the copyright/royalty is set up, K&R would not make anything by writing a third edition, which is why we haven't seen one yet. – BlackJack Sep 08 '11 at 14:24
  • @BlackJack that's a real shame. – Justin Dearing Sep 08 '11 at 14:26
  • 2
    @Let_Me_Be - How much to get the Czech translation translated back to English? :-) I think it may be the only way we'll get a C99 version of K&R... – voretaq7 Sep 08 '11 at 21:47

3 Answers3

8

You want Harbison and Steele: "C: A Reference Manual"

It explicitly covers C99 and compares/contrasts to other flavors of C. I have found it super useful.

Angelo
  • 1,614
  • 13
  • 9
8

I would still suggest (the ANSIfied second edition of) K&R for anyone who is just learning C and who wants to learn Straight Procedural C (minus objects). I'd double that recommendation if they intend to be hacking on *NIX kernel code one day as K&R truly has the "Unix Mentality" in a programming book.

Once they've grasped the basics of C syntax and have a reasonable idea of style you can introduce them to other references that talk about the C99 features and explain that it may change the way they organize what they write, but they'll have (generally) good habits from starting out with K&R (like doing declarations up front) and they'll be cognizant of the why behind doing something contrary to those habits -- I think you build better programmers that way.

voretaq7
  • 341
  • 2
  • 7
  • 3
    Doing declaration upfront is actually bad practice inherited from C89 style, variables should be declared right before they are first used. See for example [the answer to this question](http://stackoverflow.com/questions/8474100/where-you-can-and-cannot-declare-new-variables-in-c) – Étienne Nov 14 '13 at 22:08
  • 2
    @Étienne By "up front" I mean "Variables should all be declared as early as possible within the scope where they will be used." which is basically what that other answer is advocating (or at least showing in its very simplified examples). I approve of what that answer is advocating, but you want to make sure new programmers realize that "Oh drat, I need a {counter, temp variable, etc.} - Let me just declare it here in the middle of my logic." is a Bad Thing [because doing so wrecks readability like this other answer points out](http://stackoverflow.com/a/8474470/259612) (at least IMHO it does) – voretaq7 Nov 14 '13 at 22:45
  • 2
    There is no consensus, I respectfully disagree that it is a bad thing, and a lot of people think it is a good thing to declare it in the middle of the logic, see also http://programmers.stackexchange.com/questions/56585/where-do-you-declare-variables-the-top-of-a-method-or-when-you-need-them – Étienne Nov 15 '13 at 08:12
  • @Étienne That is your opinion, and you are certainly entitled to it, but to be blunt there's no way you're going to change ***MY*** opinion: I'm a cranky old Unix hacker and C coding style is very much a religious thing for me. Fortunately chances are neither of us will ever have to read the other's code :-) – voretaq7 Nov 15 '13 at 08:16
  • Hopefully we won't ;-) – Étienne Nov 15 '13 at 09:27
  • @voretaq7 The Problem in your linked answer have nothing to do with "Variables should all be declared as early as possible within the scope where they will be used.". There is the problem that the same name is used for 2 variables. You can do this with Variable declared up front (and without). – 12431234123412341234123 Jul 28 '17 at 15:13
1

I'd recommend King's C Programming: A Modern Approach. It's thicker than K&R but still not particularly padded and the author points out what is and is not new to C99 as well as style tips and other such things.