"Michael Comperchio" <mcmp...@...> wrote:
> /*********
>
> A reference to an object of type array-of-T which appears
> in an expression decays (with three exceptions) into a
> pointer to its first element; the type of the resultant
> pointer is pointer-to-T.
>
> That is, whenever an array appears in an expression, the
> compiler implicitly generates a pointer to the array's
> first element, just as if the programmer had written &a[0].
>
> *********/
>
> This is a truth.
Indeed.
> In multidimensional arrays, all but the lowest level
> array contain pointers to the beginning of the next
> level..
No, you're misinterpreting.
That arrays decay to pointers (unless they are operands
of & or sizeof) does not mean pointers are stored within
the array. It simply means that arrays are labels and
that access is achieved via arithmetic on a pointer to
the first element.
> I wish I was better at ascii graphics, I could draw
> this out..
The declaration...
int a[2][3];
...is...
|<--------- [0] ---------->|<---------- [1] --------->|
+--------+--------+--------+--------+--------+--------+
| [0][0] | [0][1] | [0][2] | [1][0] | [1][1] | [1][2] |
+--------+--------+--------+--------+--------+--------+
...not...
+-----+-----+
| [0] | [1] |
+-----+-----+
| |
| +--------------------+
v v
+--------+--------+--------+--------+--------+--------+
| [0][0] | [0][1] | [0][2] | [1][0] | [1][1] | [1][2] |
+--------+--------+--------+--------+--------+--------+
...and certainly not...
+-----+-----+
| [0] | [1] |
+-----+-----+
| |
| +------+
| v
| +--------+--------+--------+
| | [1][0] | [1][1] | [1][2] |
| +--------+--------+--------+
v
+--------+--------+--------+
| [0][0] | [0][1] | [0][2] |
+--------+--------+--------+
> The compiler will generate access code that looks
> something like this for multidimensional array access:
>
> *(*(level1 + n) + n)...
Yes, 'level1' is converted to a pointer to the first element.
It may be useful to come full circle and view this as...
* ( * (&level1[0] + n ) + n )
In a sense, level1 in the first expression is no longer
an array. It is not the array which is being dereferenced,
but a pointer to the first element.
So yes, there is a pointer _value_ involved, but that value
is not part of the array itself, rather it's a reference
to the array.
> Try preprocessing to assembler
ITYM Try disassembling.
> and check out the resulting code.
My advice to you is don't.
> It is this that I was referring to. It also behooves me
> to remember that arrays in c are contiguous blocks of a
> type. That's all. They really don't have any more of a
> special meaning than that.
Your other statements directly contradict that.
> When we are coding in c we are coding at a lower level
> that C#, or VB.
No, we're not!!
That is a mistake many authors delude people into thinking.
Why? Because they simply don't know any better!
C is a 4th Generation Programming Language. It is no less
abstract than lisp, perl, COBOL, prolog, ml, etc...
--
Peter