pointers to arrays

Ray Butterworth rbutterworth at watmath.waterloo.edu
Tue Feb 21 02:47:30 AEST 1989


In article <227300001 at uxa.cso.uiuc.edu>, fso10235 at uxa.cso.uiuc.edu writes:
> In your example, you state that E is an "array" and
> then go on to talk about &E.
> E is actually an address itself; it is the address
> of the first element of the array.  Putting brackets
> after any number merely dereferences to that number
> plus what is in the brackets.
> This is in K&R, I believe.

extern int E[10];

E is NOT an address.
E is NOT a pointer.
E IS an array.
E is exactly what it looks like.

In certain contexts however, where it is illegal to use an array,
the compiler will interpret E as &E[0] to save four keystrokes
for the programmer.  This may or may not have been a good idea.
There certainly has been a lot more than four keystrokes wasted
on the net by people arguing about this unnecessary confusion.

Similarly:

NULL is NOT a null pointer.
NULL is possibly NOT a pointer at all.
NULL is NOT part of the C language.
NULL IS a mistake.

NULL can be correctly defined as 0 on all valid C compilers.
The identifier is there simply as a comment to the programmer
to indicate that he is working with a pointer.

Too many programmers think that the compiler can understand this
comment.
Too many compiler maintainers think that they are helping their
confused programmers by defining incorrect values for NULL in
the hope that some of the incorrect code will compile correctly.

NULL is a definite mistake.
It looks like it means more than it really does.
It belongs with BREAK_LOOP, BREAK_SWITCH, and other such
well-intentioned but misleading macros.
It should either have never been introduced,
or it should have been defined as part of the language.
NULL is a mistake.  Don't use it.



More information about the Comp.lang.c mailing list