equivalence of array^pointer@@ # my take

Update — the spreadsheet is a newer post.
First let’s clarify what we mean by “pointer”.

Q: an array name is comparable to a pointer ….? Nickname? PointerObject? or PureAddress?
%%A: an array name like myArray is nickname for a pure address. See post on 3 meanings of “pointer”. However, in this post we are comparing myArray with a myPointer, where myPointer is … either a PointerObject or PureAddress
%%A: myArray is like a const ptr “int * const myConstPtr”

The apparent “equivalence” of array vs pointer is a constant source of confusion. Best (one-paragraph) pocket-sized summary — http://c-faq.com/aryptr/practdiff.html

http://c-faq.com/aryptr/aryptrequiv.html is a longer answer.

#1 (principle dealing with the confusion) physical layout. When in doubt always go back to fundamentals.

A simple array on the stack is a permanent name plate [2] on a permanent block of memory, physically dissimilar to a pointer Variable. However, Pointer Arithmetic and Array Indexing are equivalent. I feel AI is implemented using PA.

#2) syntax

Pointer variable is syntactically a more _flexible_ and more powerful construct than array. However, the strong syntactical restriction on array is a feature not a limitation. Look at strongly typed vs dynamic languages.

I feel most operations on an array is implemented using pointer operations. (Not conversely — Many pointer operations are syntactically unavailable on arrays). Specifically, Passing an array into a function
is implemented by pointer bitwise copy.

That’s the situation with arrays on the Stack. On the heap situation is more confusing. Consider “new int[5]” — return value Must be saved in a pointer variable, but the underlying is a nameless array. In contrast, see [2] above. Also, that pointer variable could rebind/reseat.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s