C For Everyone - Embedded.com

C For Everyone

C for Everyone , by Richard Man and CJ Willrich, is a new 400 page book covering the C language, with an emphasis on using it in embedded systems. I imagine a lot of embedded.com readers know Mr. Man, as he’s the principal behind compiler-vendor Imagecraft. The idea of a C book by a compiler writer appeals.

The book is well-written and almost chatty at times with a nice history of the language.

Section 1 is a short, high-level introduction to the C programming language, which is accessible to anyone wanting to learn about C. No real programming experience is required.

Section II is the real meat of the book. It provides a thorough description of C with pretty much all you need to know to build a system. There’s nothing about Windows APIs or the like; this is a book for an embedded wannabe.

It does a great job explaining types, and even has practical recommendations for deciding when to use a particular type. But, though the information is exactly correct, I disagree with the conclusion. MISRA and other standards mandate avoiding base types for all of the reasons we know, and I think the book would be better for providing that advice.

To be fair, there are lots of “Best Practices” suggestions, all of which are spot-on, and desired for C newbies. Indeed, the authors also offer valuable “Bug Trap” sidebars about oddities of the language many don’t know. For instance:

unsigned char uc =0xFE;if(~us == 0x1)…

… is bound to fail, for reasons they describe well.

Edsger Dijkstra would be horrified, but the authors describe when it makes sense to use the goto statement. They do warn that undisciplined use of the statement leads to spaghetti code. And I agree with them. While goto should be avoided, in certain (unusual) cases its use makes the code more comprehensible.

There’s practical advice, too. Two pages cover the rules for reading a complex declaration using the right-left-right rules. And there are some subjects you normally don’t see in a C book like variadic functions, recursion, and interrupt handling.

Newbies always get fouled up with pointers, but C for Everyone has a great chapter on the subject. I also recommend Understanding and Using C Pointers by Richard Reese

Oddly, with the exception of a few references, the book doesn’t cover Imagecraft’s fascinating library for Cortex-M parts. Their Jumpstart API is probably the second-fastest way to get started programming these parts. The fastest is mbed.org, which has a web-hosted tool chain so there’s no painful IDE installation required. But what makes mbed most interesting is that they have eliminated all of the peripheral programming we embedded people deal with. The Cortex-M parts have some quite complex I/O, and even the simple stuff often requires a lot of head scratching to set up. Mbed provides an API to tremendously simplify this. For instance, to configure a pin to be an input to an ADC and then read the analog, all you write is:

AnalogIn adc(p19);         // Pin 19 is now an A/D inputscale = adc.read();       // Read the A/D

The problem with mbed is that it doesn’t really scale for professional work. Sans IDE there’s no debugger so one is left using printf statements. And one must have faith that mbed will be around tomorrow; if their site disappears, so does your project.

Imagecraft sells a quite inexpensive ($99 for non-commercial work, $249 otherwise) traditional C environment with an API for Cortex-M parts that’s as easy to use as mbed’s. They support some ST parts today and plan to add many more. The book C for Everyone is part of the Jumpstart Microbox, a $99 kit including tools, the book (eBook), and an ST board with a debug link (this is for non-commercial work). Or, you can buy the eBook alone for $24.95. A printed version will be available through Amazon soon.

I do wish the book’s index were more complete (though the eBook version doesn’t really need one as it’s searchable; I was provided with an early printed book). And it’s not a beautiful work; the typography is rather pedestrian and there are few illustrations. But all-in-all this is an excellent work that will now be one of the standard suggestions I’ll give when people ask me that “how do I become an embedded programmer” question.

And they ask it a lot – 2021 times last month, which is about average.

What is your favorite book for embedded C?


Jack G. Ganssle is a lecturer and consultant on embedded development issues. He conducts seminars on embedded systems and helps companies with their embedded challenges, and works as an expert witness on embedded issues. Contact him at . His website is .

7 thoughts on “C For Everyone

  1. “Hi Jack — thanks for this review — very interesting — I think I'll have to add this one to my “Wish List” as part of my quest to become highly proficient (or, at least, less dreadful) at C :-)”

    Log in to Reply
  2. “In your first example code, ~us should be ~uc.nnnAndrei from The Great White North as seen on the Embedded.fm podcast.”

    Log in to Reply
  3. “My favorite C book is “Illustrating C” by Donald Alcock. It is easy to read and it has great diagrams that show what's happening. I found it to be very helpful when learning C. Unfortunately it is quite expensive ($89.99 on Amazon). It would be nice

    Log in to Reply
  4. “Thank you very much Mr. Ganssle for a thoughtful review of our book.nnre: the typo in the examplennIt is correct in the book, so there was probably a simple copy and paste error in the review.nnre: “the book doesnu2019t cover Imagecraftu2019s fas

    Log in to Reply
  5. “IMHO, the correct answer to any question that starts “What is the best C book for…” is always The C Programming Language by Kernighan and Ritchie. nnNo, it's not specifically about embedded coding, or systems programming, or whatever your particular

    Log in to Reply
  6. “I actually communicated with Dr. Kernighan about writing of this book. He said, (paraphrase) “go for it, write it in your own voice.” The inspiration for this book includes K&R (of course), and PJ Plauger's “Standard C”. One is conversational and one

    Log in to Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.