Advertisement

Monday, 18 September 2017

Learning to code with C

C is the world's most popular language, according to Simon Long, and he is going to show you how to use it. 

The book comes from the publishers of Magpi, a magazine which is aimed at Raspberry Pi owners both beginners and enthusiasts.  It's a short book (less than 100 pages) that leads you through a language that has the reputation of being difficult to learn.

While it is aimed at Raspberry Pi users, it can be used by any would-be C programmer. Long uses the Rasbian operating system but, from the point of view of this book, it could be almost any Linux distribution And the language details are, of course, the same no matter what operating system you use.

We start off with the ubiquitous "Hello World!" program and this is entirely appropriate because the original book of the C language by Kernighan and Ritchie was where this program first appeared.

Long moves along at a good pace with short chapters on all the main features of C. We quickly go through variables, their data types and declarations and control structures (loops and selection statements). the pace slows slightly at pointers - a difficult area for many programmers - but he manages to keep even this topic straightforward and understandable.

Functions come next, along with parameter passing (including passing values back and forth using pointers), and then more complex data, arrays, structs, typedefs and enums, which allow the construction of more complex data types.

Anyone who is already familiar with a high-level language such as Python will either be delighted , or disappointed, with the simple tools that C gives you for the construction of data structures. On the one hand they are simple, but you don't have the convenience of built-in data structure such as dictionaries and sets.

Finally, the pre-processor is discussed where among other things we find out how to make large, multi-file programs.

Long admits that he does not cover the entire language (and refers to the original K&R book for those who want to go further) but provides a good reference section at the end of the book which makes up for any omissions in the main text.

In such a short book the examples can only be trivial illustrations of the language features and consequently there are no programs that you can really get your teeth into. However, Long does a good and fairly comprehensive job of introducing the language.

The book is available to buy, or you can download a pdf for free.  See the Magpi archive here.

If you are interesting in looking at other languages for the Raspberry Pi, you might be interested to read Which Language for the Raspberry Pi


Advertisement