Why does C hate 2d arrays?

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Fri May 25 12:14:43 AEST 1990


> In article <3060 at goanna.cs.rmit.oz.au> I wrote
>                                                       Heck, if C was all
>about primitives, we wouldn't have floating point.  Why coddle these weak
>programmers by providing a sqrt() function; they have all the primitives
>they need to build it themselves.

In article <2429 at psuhcx.psu.edu>, hannum at schubert.psu.edu (Charles Hannum) writes:
> C does not provide a sqrt() function to "coddle the programmer."
> Your standard library, on the other hand, may include such a function.

Re coddling the programmer, don't you recognise irony when you see it?

This thread was concerned with ANSI C.  And the standard library *IS* part
of ANSI C.  sqrt() is not an _optional_ part of ANSI C.

> And yes, C *is* all about primitives.
> Read "The C Programming Language" if you don't believe this.

I have read "The C Programming Language", thanks, many times.
C is not about primitives.  It is about TRADEOFFS.  I repeatedly said in
my postings in this thread that C's strength comes from what it left out,
which is pretty much a paraphrase of the extract Hannum quoted in his
previous posting.

For example, malloc() is not a primitive.  In UNIX, it used to be built
on top of a _real_ primitive, namely brk().  Writing code for a PDP-11,
I often used brk() and sbrk() myself because I wanted to keep all that
library code *out* to leave room for my data.  Can anyone claim that
printf() is a primitive, with a straight face?  (I would also keep
stdio *out* too, it was much too big when I had only 64k to play with
and 30k of code and 30k of data...)

No, malloc() and printf() are tradeoffs:  the extra convenience is
worth while, and the price in terms of compiler and library support
is not too high.

The C philosophy was to provide you with ALL the primitives you need.
It was not to provide ONLY the primitives.  Adding dynamic arrays to C,
*if it could be done without disruption* would not compromise the C
philosophy in any way.  Only if programmers *had* to use the new
dynamic array mechanism *instead* of pointer arithmetic would that be so.

Any rate, all that really matters is that C should continue to work as
Eiffel's portable assembly code (:-).
-- 
"A 7th class of programs, correct in every way, is believed to exist by a
few computer scientists.  However, no example could be found to include here."



More information about the Comp.lang.c mailing list