A89: Re: (C language) Macro Expansion


[Prev][Next][Index][Thread]

A89: Re: (C language) Macro Expansion




Mark Leverentz writes:
 > Thanks!  I knew there had to be a better way to do it.

You're welcome.
 
 > I'll look into getting that book.  I assume it's not just your standard
 > beginner's introduction, right?

I wouldn't say so. Let's take a look at the authors:

Dennis M. Ritchie designed the C language and wrote a compiler around 
1972. In 1973 he and Ken Thompson (who was the father of UNIX, in
1969) ported UNIX from PDP-11 assembly to C. 

Brian W. Kernighan is known for the AWK language (in which he is the
K, beside Aho and Weinberger), this C book and the also famous 
"The UNIX Programming Environment" book, and his samisdat article 
"Why Pascal is Not My Favorite Programming Language".

Kernighan and Ritchie wrote the first edition of the book in 1978.
One of the 4 major indentation and curly brace placement style is 
also the K&R style (a.k.a. the Only True one :-) because they 
used it in this very book.

Therefore, one should assume a certain authority in it :-)

It turns out that while they are indeed very smart, their teaching
style is also superb. This book is surprisingly thin, it's about 260
pages all together. It starts with the begginer's introduction, 
printf( "hello world\n" ); and alike. On the 17. page it explains how
could you write the unix 'cat' utility using less code than the
obvious solution. In about 18 pages it goes through all C variables,
operators and expressions. It then slows down a bit and it takes into 
the 125. page to write a program that can read C declarations and decode
them (that is, you type char (*(*x()))[]() and it will print
"x: function returning pointer to array of pointer to function
returning char"). Expanding the program to handle function parameters,
qualifiers and do error recovery is left to the reader, as a light 
excercise.

Page 150 is where you are supposed to know everything you can learn
about the C language as such. The following 40 pages explain you the
I/O parts and storage allocation stuff of the standard C library, with 
examples as writing your own malloc-free and writing the UNIX "ls"
program. It is a bit unix oriented but since C vendors on other
systems try to mimic the unix interface, it's not that bad.

The remaining ~60 pages are the ANSI C reference manual (with 
explanations and examples of/for the hairier things).

I personally find this book very clear, no-BS style and actually
pleasant to read. I treat it as "The C Bible". Mind you, I've 
learned C from the first edition of this book (although I also 
have a copy of my very first C reference manual, in which 
+= still was =+ but I couldn't get hold of a compiler at those 
days... Am I old or what :-)

If you want to know more about this book or about the authors:

   http://cm.bell-labs.com/cm/cs/cbook/index.html
   
Regards,

Zoltan

PS: This book is so damned famous that a techno(?) group called 
Stale Urine uses excerpts from it in their lyrics. I'm not
kidding:

   http://www.blorf.com/su/NID/ndcitejm.html
   


References: