Array question

Steve Summit scs at adam.mit.edu
Sat Feb 16 06:45:38 AEST 1991


In article <7060009 at hpfcso.FC.HP.COM> pgt at hpfcso.FC.HP.COM (Paul G. Tobin) writes:
>Michael Stefanik wrote:
>* One thing to point out is that pointers and arrays are _not_ interchangable
>* entities _except_ when you are passing them to functions.
>
>	Michael, can you clarify this a little bit?  I thought
>pointers and arrays in C _were_ interchangeable...

It never ends.

This time, at least, the confusion is not over the difference
between pointers and arrays, but over the interpretation of the
word "interchangeable."

Michael Stefanik's statement had to do with the fact that the
declarations

	extern char a[];
and
	extern char *a;

are not interchangeable, which is a frequent misunderstanding and
is discussed at length in the comp.lang.c Frequently Asked
Questions list.

It doesn't appear that Paul Tobin is unclear on this point; I
think he is noting that a program which declares

	char a[10];

and then makes reference, in an expression, to

	a[3]

can be rewritten to make "a" a pointer:

	char *a = malloc(10);

without any change to the array-like reference.  (This is the
same point I made in a recent article about realloc.)  Actually,
there is a change: the compiler emits different code; but the
source code for the reference stays the same.

I trust we don't need to discuss any of this again right now.

                                            Steve Summit
                                            scs at adam.mit.edu



More information about the Comp.lang.c mailing list