On Wed, 09 Apr 2008 12:34:43 +0500, arnuld <arnVuld@[EMAIL PROTECTED]
>
wrote:
> I am trying hard to understand the Arrays & Pointers relation****p. Tell
> me if I am wrong:
>
>
> char a[] = "blah blah";
> char *p = "blah blah";
>
>
> ----------------------
> ARRAY | | | | | |
> | | | | | |
> ----------------------
>
> ----------------------
> p ---- ----- ----|-> | | | | |
> | | | | | |
> ----------------------
>
> this is the difference between an array and pointer to a string. Arrays
&
> Pointers are *not* interchangeable, they are *not* equal. When we pass
an
> array to a function, we are faking a pointer-phenomenon in reality
because
> arrays can not be passed to functions, when we pass an array as a
> parameter to a function, it immediately decays into a pointer to its 1st
> element and then we can access the subsequent elements using
> pointer-arithmetic. That's all we got about Arrays and Pointers
relation.
> Except this they have nothing in common.
>
I think you've got the idea, but:
- I would be careful about using 'equal'. Pointers and arrays are
different things, but they only way in C to determine equality of two
things is an expression using the == operator, and _in an expression_
an array turns into a pointer which when compared to another pointer
can indeed be equal. Since your sig refers to lispmachine, I'll point
out that LISP makes a similar distinction between EQ and EQUAL.
They actually are interchangeable _sometimes_, but not all. I like to
say 'not identical', or just 'not the same'.
- also, I wouldn't say that passing an array to a function, or in most
other uses, is 'faking' a pointer. The array (lvalue) is _converted_
to a pointer (rvalue), which is then just as good a pointer value as
any other. Maybe 'creating' or 'producing'. Or the general term for
the result of any expression/operation, 'yielding'.
- formerly david.thompson1 || achar(64) || worldnet.att.net


|