From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 1 Jun 93 06:15:44 GMT From: pipex!uknet!mcsun!sunic!news.lth.se!dag@uunet.uu.net (Dag Bruck) Subject: Re: Learning C and C++ Message-ID: <1993Jun1.061544.17079@lth.se> List-Id: In dewar@schonberg.NYU.EDU (Robert Dewar) writes: > >This certainly won't solve all your problems, and when you jump overboard >I strongly recommend grabbing onto the nearest debugger, you'll find yourself >living in it much more than you did in Ada! Advice based on personal experience, no doubt... :-) More seriously, I would strongly recommend this book: Andrew Koenig: C Traps and Pitfalls, Addison-Wesley It's a small book with a lot of substance. It does a better job than any other book at describing the unique relationship between pointers and arrays in C, which is fundamental and not very well understood by most people. It has indeed lots of good advice to offer. I think there are three idioms in C that are bewildering at first sight but very common in C code: 1. Assignment is an expression, as in x = y = z; /* not too bad */ while ((c = getchar()) != EOF) ...; /* assign to 'c' and then check what it is */ 2. Auto increment and decrement of pointers, while (*p != 0) *q++ = *p++; 3. There is no boolean data type; any integral type may be used instead. Zero is false, anything else is true. If you combine all of these you may write: while (*q++ = *p++) ; which copies an array of some type up to and including the first zero element. This is a common way to copy strings. Also note that it is different from the example in (2). With these three idioms, and in particular the last example, you have enough amunition to keep you going through a five-week flame war on Ada vs. C (:-). There is in fact some truth to it; if you look at the criticism of C, and more recently C++, you will notice that a great deal is based on permutations of these three idioms. -- Dag Bruck