JonHoyle.com Mirror of MacCompanion
http://www.maccompanion.com/archives/february2006/Books/CinaNutshell.htm

 

Newsworthy Events



C in a Nutshell

reviewed by Jonathan Hoyle



Author: Peter Prinz, Tony Crawford

O’Reilly Media, Inc.

Booksite: https://www.oreilly.com/catalog/cinanut/

$40 USD,  $56 CND, £28.50 GBP, € Euro

Published: December 1, 2005

Pages: 618

ISBN: 0596006977

Audience: Organizations interested in developing software.

Strengths: Good overall approach, grounded in practicality rather than ideology.

Weakness: Lacking illustrations and historic examples.

So, who still uses C anyway? Isn't everyone using C++ nowadays? Or C#? Or perhaps Objective C? After a moment's consideration, you start to realize that C is the core language to all of these. And with all of the books out there focusing on object oriented design and inheritance relationships, it's easy to miss the fundamental basics and library of tools that are a part of C. Moreover, the C language had a major update in 1999 by the ANSI & ISO standards committees. The original ANSI C, called C90 (since it was ratified in 1990), has had a number of books written about it over the years. However, there is now a new updated C, called C99, and compiler writers have already begun adding these new features into their C and C++ products. Unfortunately, many C programmers are completely oblivious to these new features. It is here where the authors of C in a Nutshell wonderfully explain what is now available to us.

Not designed as a tutorial, C in a Nutshell is designed as a reference for programmers to obtain quick answers to their questions. This book is divided into three parts. Part I covers the basics of the C language updated for the new millennium. The spirit of Kernighan & Ritchie can be found in these pages, which describe all aspects of C syntax, from basic loop constructs and preprocessor macros to the new variable lengthed arrays and complex data type. Part II reviews the ANSI C library and its store of tools that any programmer will find indispensable. Part III details how to create a C project with the gcc compiler.

Each chapter contains nuggets of information that even the most experience programmer will likely find new and useful. Chapter 1 covers the basics of the C language and the compiler, including the translation phases of the compilation process. Chapter 5 is one of the most interesting explanations of expressions and operators I have read. Chapter 6 details statements, including C99's new conditional expression declarations. Chapter 7 covers everything to do with functions, including variable length array parameters, which nicely leads to Chapter 8's full discussion on arrays. Chapter 9's explanation of pointers is particularly important for C99 programmers, as it give detail on how to use the new restrict qualified pointers. Memory allocation in Chapter 12 and preprocessor directives (including the # and ## operators) in Chapter 14 are also extremely interesting.

The only unfortunate aspect of the book is its narrow view of common C usage. Specifically, it ignores C as it is used within a C++ compiler. This is not a problem for the original ANSI C, since ANSI C++ is a superset of C90, and so there were virtually no conflicts. However, C99 was ratified after the ANSI C++ specification was adopted, and now there are a small number of incompatibilities between C99 and C++. Although most C++ compilers have added C99 extensions to their compilers, some extensions cannot be added due to syntax collisions. For example, both C90 and C++ have conflicting mechanisms for defining complex floating point types. In C, the syntax looks like this:

        #include <complex.h>

        float complex variable1;
        double complex variable2;


In C++, however, the syntax appears as:

        #include <complex.h>

        complex<float> variable1;
        complex<double> variable2;


The former syntax is faithfully explained in the book (p. 28); however, no hint is given that such code will simply refuse to compile if the programmer happens to be using a C++ compiler, which is extremely likely. Even the complex.h header files themselves differ between the languages and cannot be used with the other. A similar problem exists with clog, which is the complex logarithm function in C, but in C++, it is the standard iostream object for logging output (similar to cout and cerr).

Despite this small indiscretion, this is one of the finest books ever published for C programmers. Whether you are writing in C, C++, C#, or any other variant of the C language, C in a Nutshell is a must for any serious developer. This reviewer gives C in a Nutshell his highest recommendation: 5 stars.

About Us | Site Map | Privacy Policy | Contact Us | ©2005 MPN LLC.

http://www.maccompanion.com/archives/february2006/Books/CinaNutshell.htm
http://www.maccompanion.com/macc/archives/february2006/Books/CinaNutshell.htm