Book on C programming - Page 1
Forum section: electronics / general

author: GK
author_rank: Super Contributor
timestamp: August 10, 2015, 01:08:51 am
content: I am spending money. I can program in C to a useful extent but I have never picked up a book on the topic.So what is an authoritative and comprehensive reference that is up to date and preferably somewhat applicable to microcontroller programming/limitations.

author: amyk
author_rank: Super Contributor
timestamp: August 10, 2015, 01:16:48 am
content: Not specific to MCU stuff, but The C Programming Language (K&R) is highly recommended for C in general.For MCUs it depends on which one in particular since their compilers will have specific non-standard features to handle them and in that case the compiler documentation is the best source.

author: Mr.B
author_rank: Unknown
timestamp: August 10, 2015, 01:24:34 am
content: I second amyk...And add "The C++ Programming Language, 4th Edition" by Bjarne Stroustrup, ISBN-13: 978-0321563842

author: retrolefty
author_rank: Super Contributor
timestamp: August 10, 2015, 01:26:46 am
content: Quote from: Mr.B on August 10, 2015, 01:24:34 amOtherwise known as the Barney Shoestrap book.

author: Mr.B
author_rank: Unknown
timestamp: August 10, 2015, 01:28:01 am
content: Indeed...

author: kfnight
author_rank: Regular Contributor
timestamp: August 10, 2015, 02:02:57 am
content: It's not geared toward embedded, but "C Programming: A Modern Approach" is my favorite C book. It's used as a textbook though so the price can be steep for a brand new copy.http://www.amazon.com/C-Programming-Modern-Approach-2nd/dp/0393979504/ref=sr_1_1?ie=UTF8&qid=1439172064&sr=8-1&keywords=c+programming+a+modern+approach

author: tggzzz
author_rank: Super Contributor
timestamp: August 10, 2015, 08:42:17 am
content: For some of the many traps and pitfalls that need to be avoided in C and C++, I find the "frequently questioned answers" to be refreshingly honest. Seehttp://yosefk.com/c++fqa/

author: tggzzz
author_rank: Super Contributor
timestamp: August 10, 2015, 08:59:22 am
content: Quote from: mojo-chan on August 10, 2015, 08:45:49 amTrue. Consider understanding MISRA C and why it needs to exist. There are similar concepts for other environments.

author: Karel
author_rank: Super Contributor
timestamp: August 10, 2015, 09:08:38 am
content: K&R is a perfect starting point. After that, keep this book at hand:C in a nutshell (from O'Reilly)It's one of the best references I found so far.Also, to improve your skills, read this book, it's a lot of fun:Expert C Programming: Deep C Secrets

author: TerraHertz
author_rank: Super Contributor
timestamp: August 10, 2015, 01:09:29 pm
content: "up to date and preferably somewhat applicable to microcontroller programming/limitations."The only way to meet both those requirements, is to buy a cross compiler applicable to the particular micro you're thinking of using. Because the features, library & limitations of that particular compiler/linker/asm toolset will be what you have to live with. HiTech C for instance, used to have many target processors. Apparently now it's owned by Microchip and only targets PICs. Bummer.In a more general sense, the theory and methods of micro programming in C don't really change. So you can get some older books cheap. Like 'Programming Embedded Systems in C and C++' Michael Barr (O'Reilly)http://www.abebooks.com/servlet/SearchResults?an=Michael+Barr&sts=t&tn=Programming+Embedded+Systems+in+C+and+C%2B%2BEdit: Oh, another old but good one: Writing ROMable Code Using Microsoft C/C++. By Systems & Software Inc. Author: Wilson C Chan. Oct 1993.This was one of the manuals that came with a package called CV/Tools, Embedded Development Kit.You might find one 2nd hand.

author: John Coloccia
author_rank: Super Contributor
timestamp: August 10, 2015, 02:53:50 pm
content: Quote from: tggzzz on August 10, 2015, 08:42:17 amIt's difficult to argue with a lot of what's written there. Near and dear to my heart is "No Reflection". Really, a glaring omission. I've always ended up building templated, callback classes so at least I'd have type-safe callbacks. Really, it worked very well, but it's frustrating that it needed to be done at all.D is quite a bit better in many respects. I guess the guy pissed off Stroustrup at some point, but I wish D would become a lot more popular. C++, as good and powerful as it is, has a large number of flaws and poor design decisions.As far as books are concerned, what's the point? There is so much information available online that the idea of learning a programming language via a book seems really antiquated. It's so much more effective to refer to the myriad online resources, and have reference and project right there in front of you at the same time. You'll learn very quickly that way.And line up your braces...

author: Howardlong
author_rank: Super Contributor
timestamp: August 10, 2015, 03:41:42 pm
content: I haven't opened K&R for a very long time, is it still the original K&R edition or has it been updated to one of the ANSI revisions?Being predominantly a Pascal and assembly language programmer back in the mid to late '80s, I'd been teaching myself C using pre-ratified ANSI C in Microsoft and Turbo C in my own sweet way as only a Pascal programmer could. I remember finally learning C 'properly' by cutting my teeth on someone else's K&R code which was full of seemingly write-only pointer arithmetic.I don't think many people write in K&R any more.

author: tggzzz
author_rank: Super Contributor
timestamp: August 10, 2015, 03:56:55 pm
content: Quote from: John Coloccia on August 10, 2015, 02:53:50 pmI'm less concerned about the lack of reflection since in the RT arena there are more important problems, especially related to the lack of a memory model and the effect that has on multithreading/multiprogramming libraries. The latest C has, I believe, started to catch up in this area (only >20 years too late).Memory models are difficult to get right; even Java, had to make significant modifications a little over 10 years ago. Fortunately few applicatin developers noticed the changes.As for "unfortunate" design choices, I'm particularly fond of the endless "casting away constness" arguments 20 years ago; they emerge inhttp://yosefk.com/c++fqa/const.htmlIt would be quite hilarious if it wasn't so serious.

author: Ian.M
author_rank: Super Contributor
timestamp: August 10, 2015, 08:05:17 pm
content: As many cross compilers for embedded systems only partially implement C99, its advisable if writing portable code to stick to the C89 standard.K&R 2nd ed. covers ANSI C89/ISO C90 and is still useful. An original (1st ed.) K&R isn't much use nowdays.Also see:http://publications.gbdirect.co.uk/c_book/

author: Howardlong
author_rank: Super Contributor
timestamp: August 10, 2015, 08:25:52 pm
content: Quote from: Ian.M on August 10, 2015, 08:05:17 pmGood to know, I was concerned that readers might think that the original 1st ed. K&R was representative of what's used today. In retrospect, I think I was somewhat lucky, picking up ANSI C off the bat myself but then having to dive into someone else's K&R. I remember rewriting it into ANSI C and porting it to a DLL in Windows 2.0, all pretty bleeding edge in those days.

author: nctnico
author_rank: Super Contributor
timestamp: August 10, 2015, 08:44:04 pm
content: This book (Making Embedded Systems) about programming in C got recommended in a different thread. Seems interesting.http://shop.oreilly.com/product/0636920017776.do

author: Galenbo
author_rank: Super Contributor
timestamp: August 11, 2015, 08:51:32 am
content: Quote from: TerraHertz on August 10, 2015, 01:09:29 pmMost useful info till now, that complies with my expierience.

author: GK
author_rank: Super Contributor
timestamp: August 12, 2015, 11:10:05 am
content: Okay, thanks for the suggestions. I just purchased The C Programming Language (ANSI C Version), Second Edition and the Stroustrup book on Abebooks for chump change. That should keep me satisfied for the time begin.

author: abebarker
author_rank: Contributor
timestamp: August 12, 2015, 04:49:41 pm
content: This is not a book but it is a lot of in-depth information mostly on the C language. I found it rather enlightening.Programming Paradigms (Stanford)https://www.youtube.com/playlist?list=PLD28DAB58144B6BFC