comp.lang.ada
 help / color / mirror / Atom feed
From: pipex!uknet!mcsun!sunic!news.lth.se!dag@uunet.uu.net  (Dag Bruck)
Subject: Re: Learning C and C++
Date: 1 Jun 93 06:15:44 GMT	[thread overview]
Message-ID: <1993Jun1.061544.17079@lth.se> (raw)

In <comp.lang.ada> 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

             reply	other threads:[~1993-06-01  6:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-06-01  6:15 Dag Bruck [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-06-03 12:48 Learning C and C++ Robert Dewar
1993-06-02 19:08 Robert Kitzberger
1993-05-31 13:18 LEARNING C AND C++ Bjarne Stroustrup
1993-05-29  0:12 cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!howland.
1993-05-28 20:22 Learning C and C++ Robert Dewar
1993-05-28 18:20 Step he Leake
1993-05-28  9:00 Peter Hermann
1993-05-27 10:14 agate!howland.reston.ans.net!torn!nott!bnrgate!bnr.co.uk!zaphod.axion.bt.
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox