Read an Excerpt
PREFACE:This book is designed to help current C users become proficient in ANSI C quickly. Rather than describe ANSI C completely, and expect the reader to notice what's new, we present a list of changes from the common dialects of C (K&R, BSD 4.3, System V.3, and a scattering of others) that a user of ANSI C should know about.
ANSI has changes ranging from the critical to the truly nitpicky. There are two kinds of critical changes. The most important are "quiet changes". These are changes in behavior without a change in syntax; in other words, existing code might act differently than it did under existing implementations, but the compiler can't warn you about it. Of course, some quiet changes are also unlikely to bite you, but the fact that you won't get warned by your compiler about the change in behavior makes it necessary to tell you about them anyway. The other critical changes are changes in syntax, which might require you to change your code to compile it under ANSI C.
We have split the book into two main sections, one for the language itself (including the preprocessor) and one for the library routines that provide run-time support. The language section is organized by category: tokens, the preprocessor, declarations, expressions, statements, and future directions. The library section is ordered by header file from most to least basic.
If you want to get a jump-start on ANSI C, you can scan the book for only the critical changes, which are marked by bars in the margin. However, it's a good idea to come back later and read the whole book, or you'll get bitten by something rarer or more subtle.
We also describe some techniques for making your code compile with bothpre-ANSI and ANSI compilers. Until every system in the world is ANSI compliant, many programs will have to compile on both kinds of systems. These tricks are interspersed in the text where they are relevant.
Rather than merely recite changes, we have made an effort to describe unobvious reasons for them. This is for more than historical interest; we think it will be easier to remember what has changed if you know why it has changed. It can also sometimes help eliminate frustration by letting you know that the ANSI committee sometimes had no real choice, for reasons that may not be obvious. You will be annoyed and even angered by their decisions often enough; we thought to reduce this annoyance by giving you the excuses, although you - or even we - might not think them sufficient.
Although we are trying to present the material in a small place, we have not always been able to prevent our opinions on changes from creeping in. We do not view this book as a commentary on ANSI C, rather as an explanation of it. However, our writing style is more conversational than that of many technical tomes, and sometimes we could not simply describe a particular travesty without making it clear that we did not approve. Otherwise we could never look at our reflections in the monitor again.
The book is written in the first person because only one of us was writing text at any give time. As regular readers of the C Advisor column in UNIX Review may note, the writing style is strongly Ken's. We hope you will read it anyway.
Primarily we have designed this book to be useful, rather than precise to the point of numbness; we are not reprinting the ANSI standard. We hope it is readable as a book, concise as a reference, and soon obsolete as you put this transition behind you and get on to doing things with the language instead of worrying about it. We suspect it might also make a pretty good flyswatter.
We would like to thank Steve C. Dewhurst, Patricia Giencke, Brian W. Kernighan, Douglas B. Robinson, and Clovis L. Tondo, for their diligent, helpful, and very insistent reviews. What errors remain in this book after their thorough work are hopefully insignificant, and are, in any case, completely our fault. We would also like to acknowledge Walter Murray's helpful discussions about some arcane edges of the standard. John Wait and the crew at Addison-Wesley suffered these novice authors with amazing forbearance and provided critical help and equipment. CPU cycles were supplied, in large part, by Kee Hinkley and his Amazing In-Home Computer Center.
This book would also not have been possible without the support of our families. Ken's wife, Susan D. Jones, and her mother Jill S. Jones, shouldered Ken's share of parenthood at long and odd intervals so that he could be an author when he probably ought to have been being a father. For that, and for monopolizing the home computer, he asks Jareth and Corwin's understanding (with a small bribe in the college fund department). John thanks his wife Judy for her faith and for yielding precious weekend time; also his father for his love of the mind.
13 October, 1991