21st Century C

This was originally printed in the March 2013 edition of the UKUUG newsletter, which is now defunct.

Title: 21st Century C (1st edition – a 2nd edition is available)
Author: Ben Klemens
ISBN: 9781449327149

Not having touched much C since university – when a trusty copy of K&R was my guide to the language – I was intrigued by the title of this book which claims to cover modern C. A word of warning up front however: this book assumes the use of C99, and in some cases C11. Most compilers support C99, but there is a great big gap in the form of Visual C++. The author’s suggestion if you want to compile C on Windows is basically ‘install Cygwin’.

The preface and first chapter largely set the scene, and reveal some of the author’s prejudices against interpreted languages, C++ and Windows (these show up throughout the book). The chapter on debugging, testing and documenting provides a good overview of these subjects, although detailed coverage would be a book in itself. The third chapter covers packaging – or perhaps ‘compiling’ would be more accurate. This is worth reading solely for its explanation of how autotools works. This is complemented by the following chapter on version control, which doubles up as a Git tutorial.

The middle section of the book focuses on the language itself. The first chapter in this section covers the thorny issue of pointers, and does a good job of explaining the different ways of allocating memory, as well as pointer arithmetic. Chapter seven covers some C syntax which, according to the author, you can ‘ignore’. Some of these are arguable either way (e.g. not returning a value from main() is fine if you’re happy to specify C99 as a minimum), others are a bit more controversial – such as using goto but avoiding switch. The chapter on text handling spends a lot of time explaining how Unicode works, although most readers can skip to the final page with the notes on gettext.

The penultimate chapter is the most confusing of the book, covering object orientated C. The overall message seems to be that OOP is bad (as are C++ and Java), but that you can accomplish some of the same things if you use bits of C11. The end result appears to be fairly unreadable code, and this chapter can be safely skipped. The final chapter covers some popular libraries such as pthreads and libxml. However, the space available means that this is necessarily a brief overview and you will need to read the separate documentation to move beyond basic examples.

The only potential issue you may find with this book is that the author describes specific tools rather than general techniques. For example, the chapter on version control is really a brief introduction to Git – Subversion users will find little of use here. If you already use the author’s preferred tools, or are able and willing to switch, then this is a good all round collection of tips and advice on C programming – not just the language but also the surrounding environment.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

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