C'mon, guys!

Guy Harris guy at sun.uucp
Wed Jun 4 14:08:03 AEST 1986


> Or do we have confusion between name and object?
> ...
> So an array is not a pointer but a reference to an array
> in an expression is a pointer.

That's part of it, but I strongly suspect that people have been confused by
the fact that when you use an array name in an expression it really means a
pointer to the first member of the array; they interpret this limited
interchangability as meaning pointers and arrays are equivalent.

There's been a discussion in net.lang.c of features to be added to C;
sometimes I think pointers should be *subtracted* from C, since people seem
to get very confused about them.  There's plenty of code out there which
indicates that the author thinks that, because the second argument to "stat"
is a "struct stat *", that you *have* to pass it a variable of type "struct
stat *" as its second argument; they declare such a variable, set it to
point to a declared "struct stat", and pass the variable to "stat" instead
of just "&<the struct>".  Of course, there's always the code which doesn't
declare the "struct stat", and doesn't initialize the pointer, but just
passes a pointer which points nowhere to "stat"; this pops up every so often
on net.lang.c with the question "Why doesn't this work?" attached.

OK, maybe they're useful, and shouldn't be removed.  C classes should spend
*lots* more time on them than they are doing, though, given these problems;
better that people learn in class before they start writing code, than be
forced to ask several thousand people on USENET why their code doesn't work.
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.com (or guy at sun.arpa)



More information about the Comp.unix mailing list