Learning C programming, C99 or not

OK, so it seems like it's time to really learn some C considering how much used the language is in the open source world. When first learning C I want to do it "the right way", if it's possible to say such a thing.

ANSI this, and ANSI that... should it be C89, or would it be OK to go for C99, or would that break portability in some way? I will mainly spend my time coding on BSD, but maybe also on other operating systems. I also have some plans on reading some of the UNIX programming books I see smiling at me over at amazon.com, but I don't think they teach you C, and that's why I need a C book as well.

It seems like most C programming books today use C99, but I could be wrong. I know the book "C Programming Language" by K&R (uses C89?) is very popular, but it's old, and its layout isn't what I would call nice looking. I've also heard some complaints about the language used, and the authors showing of their vocabulary which isn't something that will suit my English skills since that's not my native language.

Any suggestions or recommendations would be highly appreciated!
 
The big difference is K&R C versus ANSI/ISO C. The differences between C89 and C99 are very minor, and most people never stumble across them. Any C book within the last fifteen years will be more than adequate.
 
I have C/C++ Programmers Reference 3td edition by Herbert Schildt, 2003

I like this reference.
It also mentions differences between C98, C99, C++ (and maybe ANSI, i'm not sure, i don't remember)

There is 4th edition available (If i recall correctly they added little C# in it)

Another quite good book i have is How to program C, i think it's pretty well written, and gives not only understanding how to code C, but also various tips how to improve performance, how to reduce bugs, how to make readable code.... etc

Side note:
Aside from that Advanced programming in the UNIX Environment is waiting it's turn to be read
 
killasmurf86 said:
I have C/C++ Programmers Reference 3td edition by Herbert Schildt, 2003

Sorry... I can't let this pass. Every Schildt book I've ever seen has been of the lowest imaginable quality replete with errors perpetuated by the recycling of material from similar previous books by the same author and presumably unchecked. Maybe he's improved in the last decade... though I doubt it.

Now that's out of the way :) I like the O'Reilly published "Practical C Programming" and "Mastering Algorythms with C", not forgetting the quite invaluable "C Pocket Reference" which is an excellent quick reference and one of the more "meaty" pocket guides.
 
trev said:
Sorry... I can't let this pass. Every Schildt book I've ever seen has been of the lowest imaginable quality replete with errors perpetuated by the recycling of material from similar previous books by the same author and presumably unchecked. Maybe he's improved in the last decade... though I doubt it.

Now that's out of the way :) I like the O'Reilly published "Practical C Programming" and "Mastering Algorythms with C", not forgetting the quite invaluable "C Pocket Reference" which is an excellent quick reference and one of the more "meaty" pocket guides.

My book is translation to Russian... Perhaps it's a little different.
(all my book are translated to Russian. I don't like using e-shops to get books, otherwise all my books would be English)
 
Thank you all for your suggestions. I'm still not sure which book to go for, but I'm checking out every book mentioned here.

Doesn't it matter if I choose a book that uses K&R C, ANSI/ISO C (or C99) when it comes to portability?
 
Don't use K&R for anything except learning the history of the language. It's horribly out-dated and no longer used anywhere (that matters). Use/learn ANSI/ISO standard C.
 
phoenix said:
Don't use K&R for anything except learning the history of the language. It's horribly out-dated and no longer used anywhere (that matters). Use/learn ANSI/ISO standard C.

What about K&R 2?
 
trev said:
Every Schildt book I've ever seen has been of the lowest imaginable quality replete with errors perpetuated by the recycling of material from similar previous books by the same author and presumably unchecked.
Counting errors in Herbert Schildt's books on C is considered a decent random generator :e

trev said:
I like the O'Reilly published "Practical C Programming" and "Mastering Algorythms[sic] with C", not forgetting the quite invaluable "C Pocket Reference" which is an excellent quick reference and one of the more "meaty" pocket guides.
I in turn highly recommend "Expert C programming - Deep C Secrets" by Peter van der Linden. It is by no means a tutorial (it's for people who already know C but want to get better at it), but it is rife with amusing anecdotes, thought-provoking exercises and very practical tips and tricks. Very insightful.

Fonz
 
randux said:
What about K&R 2?
That's ANSI-C a.k.a. C89 a.k.a. C90. It's not the newest standard but many current compilers still don't fully support that anyway. C89/C90/ANSI-C as described in K&R2 is still perfectly fine. Get the book, read it from cover to cover and do the exercises. The old saying "You program in C, you buy this book" still applies.

Fonz
 
I also recommend C: A Reference Manual, by Harbison and Steele, currently in its 5th edition (2002). It's not a tutorial, but if you want the real nitty gritty on some language construction and what will be portable between dialects of C and what may not be portable, this is the one to get.
 
I suggest, that you start with the latest ISO C:
The current standard for Programming Language C (C11) is ISO/IEC 9899:2011, published 2011-12-08. Technical Corrigendum 1 (ISO/IEC 9899:2011/Cor. 1:2012) was published in 2012.

An almost final draft of this standard (.pdf having 700 pages) is available for public download. The final ISO document is very expensive (CHF 238 = ca. US$ 250), and so I personally stay with the draft.

For quite some time, FreeBSD has been urged to stay with the quite old GCC 4.2.1 because of the GPLv3 issue. More current GCC (4.6 to 4.8), do already support some C11 features, and the respective command-line switch -std=c11 is honoured. The same holds for clang. In FreeBSD 9, clang 3.1 is in the base as an optional compiler to GCC 4.2.1, and clang 3.2 is available from the ports. FreeBSD 10 is said to come with clang as the default compiler, and so C11 will automatically belong to FreeBSD's premier league of supported C dialects.

Anyway, the changes from C99 to C11 are not that radical. So, if you learn C11, then C99 and C89 would be included.

Finally, learning a C language dialect serves only for half of the battle, and regardless of what C dialect you learn, you want also to become comfortable with the C library. My preferred reading for this is the Manual of the GNU C Libray. There are HTML and PDF versions. The very well laid-out PDF got 1000 pages with page links in the Table of Contents and it comes with various indexes.
 
graudeejs said:
Aside from that Advanced programming in the UNIX Environment is waiting it's turn to be read

I was reading that the other day. Stevens books are good. I like the TCP one as well.

There are some new books this year that may be of interest. The orielly one talks about make files so it's more of a world book. There is also one in the head first series.

Both K&R ansi and UNIX Programming Environment are good for beginners. Learn to make your own fgrep() and wc(). Also K&R is just awesome for just having practical advice. Kernighan communicates better than some teachers and simply a joy to read.

If your really beginning C you almost need two books. K&R and something else.
 
C99 has restrict pointers and inline functions (which are very confusing compared to C++ inline) ... these are the biggest reasons you should learn C99.

C99 struct initialization is nice as is the variadic macro support. It also has some other niceties that were standard in POSIX prior to C99.

C99 also supports dynamically sized arrays (e.g. int array[n]; though Fortran has supported this for decades). I guess it's a good feature ... I personally don't use it though you don't need to worry about freeing memory.

EDIT: Duh, the original post date ...
 
One does not simply learn programming language from reading books. Same like surgeons do not learn operating from books, but purely from practice and observation. Maybe they will help you to understand the basics but will not teach you how to program for sure. Human brain is just hardwired like that.
 
Back
Top