In a world where new JavaScript frameworks come and go almost daily, whywould you dive into an aging, bare-bones language like C? Well, for one, if you hope tokeep up with all those framework fads (ouch, opinion alert), you might want a backgroundin just such aging, bare-bones technologies that provide a foundation for so manymodern languages. Did you look up popular programming languages on a site likeTIOBE and find C consistently at the top?Maybe youre interested in the amazinglyadvanced video cards and want to see how the software that drives them works.Or perhaps youre exploring newerand much smallergadgetslike Arduinos and heard that C is the right tool for the job.
No matter the reason, its great to have you here. All of those reasons are valid ones,by the way. C is a foundational language and understanding its syntax and quirks willgive you a very long-lived computer language literacy that will help you pick up newlanguages and styles more easily. C (and its cousin C++) are still widely used whenwriting low-level code for device drivers or operating systems. And the Internet ofThings is breathing new life into microcontrollers with limited resources. C is a greatfit for wringing the most of those tiny environments.
While Ill be focusing on that last idea of writing clean, tight code for tiny,limited machines, Ill still start with the basics of computer programming andcover a variety of rules and patterns that apply to C anywhere you might find it.
How to Use This Book
This book aims to cover all the basics of good C programming for any of thesituations mentioned above. Well look at control structures, operators,functions, and other elements of Cs syntax along with examples of alternatepatterns that can shave a few bytes off the size of your compiled program.Well also be looking at the Arduino environment as a great application forlean C code. To best enjoy the Arduino section, you should have some basic experiencewith building simple circuits and using components like LEDs and resistors.
Heres a preview of the chapters:
A brief look at the history of the C language and steps toset up your development environment.
An introduction to statements in C, including basic I/O,variables, and operators.
Here I cover branching and looping statements and go alittle deeper on variables and their scope.
A quick return to storing data. I show you Cs facilitiesfor manipulating individual bits and storing lots of bigger things in arrays.
Ill look at how to break up your code into manageable chunks.
Getting a little more advanced, I create more complexdata structures and learn how to pass them to, and return them from, functions.
Learn how to find and use popular bits of code that can help youwith common or intricate tasks.
The real fun begins! Well set up the Arduinodevelopment environment and make some LEDs blink.
Try out several electronic peripherals including sensors,buttons, and LCD displays with complete Arduino projects.
Learn some tricks for writing code especially designed tohelp small processors get the most out of their resources.
Build on your C library skills with tips and tricks forwriting friendly, well-documented libraries compatible with the Arduino IDE.
Try a quick Internet of Things project with a few parting thoughtsand some ideas for what to try next as you continue to improve your lean coding skills.
The appendices include a handy collection of links to the hardware and software Iuse, as well as information on downloading and configuring the C and Arduino examplesshown throughout the book.
Conventions Used in This Book
The following typographical conventions are used in this book:
ItalicIndicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.
Tip
This element signifies a tip or suggestion.
Note
This element signifies a general note.
Warning
This element indicates a warning or caution.
Using Code Examples
Many of the code examples in this book are quite succinct, and youll often benefitfrom typing them in by hand. But that isnt always fun and sometimes you want to startwith a known, working copy and modify stuff. You can grab the source for all of the examplesfrom GitHub at has detailed instructionson downloading the code and setting up the files for use with your development environment.
If you have a technical question or a problem using the code examples, please send an email to .
This book is here to help you get your job done. In general, you may use the example code offered with this book in your programs and documentation. You do not need to contact us for permission unless youre reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing examples from OReilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your products documentation does require permission .