Seven Original Sins of K&R (Long)

Joe English Muffin jeenglis at alcor.usc.edu
Fri Sep 28 11:21:49 AEST 1990


tom at ssd.csd.harris.com (Tom Horsley) writes:
>The eight (and worst) original sin was allowing arrays to (sometimes) be
>kind of automatically converted sort-of into pointers to the first element
>of the array except when they aren't.

C's array semantics make perfect sense once you
understand C's *pointer* semantics, which are probably
the most unique (and elegant, IMHO) feature of the
language.

The only wart I can see on the language wrt. arrays
is that

    int foo(bar) char bar[]; { ... }

is legal syntax.

>Without a doubt this psuedo
>equivalence between arrays and pointers that works most of the time except
>when it doesn't has caused more confusion and twisted more brains of people
>trying to learn C than any other feature.

Actually, it's probably _strings_ that have boggled
beginners with backgrounds in BASIC, causing confusion 
and core dumps, dismaying dozens of dumbfounded dopes,
than anything else.  How many times have *you* seen
a C neophyte go nuts trying to figure out why
'string1 = strcat(string2,string3);' doesn't
work as expected?  Of course, strings make perfect
sense too once you understand pointers.

I hardly consider these things an 'original sin.'
They're natural extensions of a fundamental part
of the language, which is really quite simple
to understand.


--jeenglis at alcor.usc.edu



More information about the Comp.lang.c mailing list