LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   C pitfalls book recommendation (http://www.linuxquestions.org/questions/programming-9/c-pitfalls-book-recommendation-656233/)

easuter 07-16-2008 06:31 PM

C pitfalls book recommendation
 
I've been learning C for the last few weeks and have made some good progress; but as the "practice" programs I write start getting more complex I was thinking of buying a book with common C pitfalls, something along the lines of Prentice Hall's "Efective Java".

Of the few books I found on amazon one was released in 1994 and the other in 1989, so both are pre-C99 and the book reviews are almost as old too:(

Any pointers would be appreciated ;)

tronayne 07-17-2008 06:20 AM

A really good book -- one that I use as a textbook for teaching "intermediate" and "advanced" C -- is Steven Kochan and Patrick Wood Topics in C Programming (rev.ed.; New York: John Wiley & Sons, Inc., ISBN 0-471-53404-8, 1991). This book, along with a couple of others by the authors, is excellent -- see http://www.kochan-wood.com or Amazon -- and is written for Unix and Unix-like systems.

About the age -- C hasn't really changed all that much since the ANSI standard was adopted (and there's no reason that it should, if you think about it). What has changed, though, are vendor "enhancements" (which you should avoid like the plague). If you're going to get serious, you really need to pay attention to writing code to ANSI/ISO standards (avoiding all vendor-specific library routines and the like; the will come back and bite you). Kochan and Wood books are well-written, provide working examples for every subject, and, for my money, you can't go wrong.

Hope this helps some.

easuter 07-17-2008 07:41 AM

Thanks tronayne, I will take a look at that book. :)

About learning standard ANSI/ISO C, I think I am already on the right track there. I'm following Stephen Prata's "C Primer Plus" (5th ed.), which according to the author, strictly follows the standard C library.

ocicat 07-17-2008 09:31 PM

Quote:

Originally Posted by easuter (Post 3216991)
...but as the "practice" programs I write start getting more complex I was thinking of buying a book with common C pitfalls, something along the lines of Prentice Hall's "Efective Java".

One of the best books on C (next to The C Programming Language...) is surprisingly called C Traps & Pitfalls by Andrew Koenig:

http://www.amazon.com/C-Traps-Pitfal...6348112&sr=8-1

Koenig is one of the AT&T elite from the same generation as Ritchie, Thompson, et. al.

easuter 07-18-2008 06:26 AM

I think I will get both books.
"Topics in C Programming" seems to be the next book I would need anyway after finishing with the one I'm busy with.

Some other books from Kochan & Wood also seem to be well worth reading too.

Thanks everyone! :)

FranDango 07-18-2008 08:20 AM

Most C programming books will do, unregarded their age. I suggest Googling for C/C++ topics, because proper coding, pitfalls, coding style etc are favoured topics among C/C++ programmers and a lot of good essays are spread out on the net. Universities have a lot of this stuff. Philip Machanick had a good tutorial on C/C++ called "C and C++ in 5 days" for those in a rush. Should be available somewhere on the net.

Linux Archive

resetreset 07-19-2008 07:00 AM

i was just wondering if this would be a good place to tell everyone my opinions on C - i hate it, mostly, but maybe i'll start a new topic. to the OP - can i ask WHY you're learning C?

easuter 07-19-2008 11:19 AM

Quote:

can i ask WHY you're learning C?
I'm doing Computer Science, so at some stage I will have to work with it.
But thats not my only reason; C is a very powerful language, and although that also means that application development might be a bit harder than say Java, there is almost no limit to what you can accomplish using C.

I really enjoyed working with MIPS assembly last semester and since C gives the same power and speed as assembly does but in a higher level form, I feel like I would benefit from learning it.
Besides, I think its fun. :)

resetreset 07-20-2008 05:14 AM

Quote:

Originally Posted by easuter (Post 3220013)
I'm doing Computer Science, so at some stage I will have to work with it.
But thats not my only reason; C is a very powerful language, and although that also means that application development might be a bit harder than say Java, there is almost no limit to what you can accomplish using C.

I really enjoyed working with MIPS assembly last semester and since C gives the same power and speed as assembly does but in a higher level form, I feel like I would benefit from learning it.
Besides, I think its fun. :)



Ahh yes, if you're doing computer science, it's probably good and *exactly* for the reason you say - but do you realise where it came from? If you're already a little familiar with it, post your guesses, I really want to chat about this with someone.
Do you realise that you're not supposed to be able to malloc in a HLL? Defining an array subscript is enough.
And why, WHY, do you have to define everything (vars and funcs) before you can use them? WHY? Why is the compiler so dumb?

easuter 07-20-2008 06:03 AM

Quote:

And why, WHY, do you have to define everything (vars and funcs) before you can use them? WHY? Why is the compiler so dumb?
Umm...declaring variables is the SANE way to do things. It makes it easier to keep track of variables and to debug the program.
Creating variables as you go along might be ok in a small scale project (say a simple bash script), but its a sure way to create unnecessary headaches in a larger project.

And about "defining" functions...what do you mean? You have to create the damn things before you can use it :rolleyes:
Maybe you are talking about function prototyping, in which case I dont see any problem with that either.

Quote:

but do you realise where it came from?
Where C came from? AT&T Bell Labs...but why does that matter?

jiml8 07-20-2008 12:37 PM

Quote:

Originally Posted by resetreset (Post 3220501)
And why, WHY, do you have to define everything (vars and funcs) before you can use them? WHY? Why is the compiler so dumb?

Because by doing this you eliminate a whole class of errors, that otherwise can send you on extended, twisted, and infuriating bug hunts when your HOL implicit typing leads to the wrong type! By doing this, you tell the compiler that: "yes, this really IS the way I want it" rather than letting the compiler assume.

C is my favorite language, and I speak several assemblers, C, C++, C#, numerous dialects of Fortran, several dialects of Basic, perl, PHP, some Java, a bit of Python, and some other languages you've never heard of.

resetreset 07-21-2008 03:14 AM

Quote:

Originally Posted by easuter (Post 3220545)
Umm...declaring variables is the SANE way to do things. It makes it easier to keep track of variables and to debug the program.
Creating variables as you go along might be ok in a small scale project (say a simple bash script), but its a sure way to create unnecessary headaches in a larger project.

And about "defining" functions...what do you mean? You have to create the damn things before you can use it :rolleyes:
Maybe you are talking about function prototyping, in which case I dont see any problem with that either.


I mean before you can do int jump { jump ; }or whatever, you have to say "int jump();" just by itself - THAT thing.



Where C came from? AT&T Bell Labs...but why does that matter?


No - why was it created? In the 70s or whenever they were making it, high level languages were just about starting to be designed and made - if you've programmed in assembly, of course you'll realise that a pointer is a [] is asm (indirection), AND C has malloc - so, like a good comp sci student, care to take a guess what the purpose behind inventing it was? :)


All times are GMT -5. The time now is 03:04 AM.