Aw: Well defined meaning of pointer to an array

S

Syron

Just to put some oil into to fire... What is the following, Paul?

struct Foo {
int data[100];
};
int* bar = (int*)(new Foo);

The fact is that bar points to simply data, nothing else. The language structs/type-system are helpers for interpreting data the right way. Data and its interpretation (here as an int) is absolutely independent, thus it can be considered a nice coincident here that the second declaration points to astorage area that has been declared as an int earlier.

Arrays are only unaligned, continious storage areas of the same type, and the fact that an array alias (in the sense of "alias of a storage area") canbe implicitly converted into a pointer is just a convenience thing to iterate over the array elements.

Thus, when you write something like:
int A[100];
int* B = A;
B is both a pointer to an int as well as a pointer to an array of ints.

But my personal opinion is to call them the following:
- A is an alias for a storage area of the size of 100*sizeof(int).
- B is an alias for a storage area that can hold an address of memory.
- When dereferenced (by an array index specifier or by a pointer dereferencing asterisk), the memory referenced gets interpreted as an int.
- The fact that the elements at B+n*sizeof(int) with 1<n<100 /also/ have been declared as ints is nice, but nothing else.

By the way, 0x3f000000 interpreted as a float is 1.0.

(No, I'm no expert, but I spent some time thinking about ... Paul. These are some conclusions about my thoughts, and maybe they're wrong.)
 
P

Paul

Just to put some oil into to fire... What is the following, Paul?

struct Foo {
int data[100];
};
int* bar = (int*)(new Foo);

The fact is that bar points to simply data, nothing else. The language
structs/type-system are helpers for >interpreting data the right way. Data
and its interpretation (here as an int) is absolutely independent, thus it
can >be considered a nice coincident here that the second declaration
points to a storage area that has been >declared as an int earlier.
This same concept can be represented by a void pointer.
void* p= almost_anything;

Remember a pointer doesn't alwas point to simple data , it may point to a
function for example. I prefer to think of a pointer as pointing to an
entity. This way its suitable for pointing to functions, arrays, polymorphic
types and simple data types.
Arrays are only unaligned, continious storage areas of the same type, and
the fact that an array alias (in the >sense of "alias of a storage area")
can be implicitly converted into a pointer is just a convenience thing to
It's not just a convenience, its the underlying techincality because
historically an array is a pointer+offset in von neuman architecture. I
don't know of any system that has any other technical implementation.
Thus, when you write something like:
int A[100];
int* B = A;
B is both a pointer to an int as well as a pointer to an array of ints.

Yes I totally agree.
An array of ints is an entity that could be described as a contiguous
sequence of ints..
But my personal opinion is to call them the following:
- A is an alias for a storage area of the size of 100*sizeof(int).
- B is an alias for a storage area that can hold an address of memory.
- When dereferenced (by an array index specifier or by a pointer
dereferencing asterisk), the memory >referenced gets interpreted as an int.
- The fact that the elements at B+n*sizeof(int) with 1<n<100 /also/ have
been declared as ints is nice, but >nothing else.
I think it should be 0<= n < 100.
What do you mean by "it's nice but nothing else"?
It's not just a random consequence that happens to be nice. It's the way
it's guaranteed to be, by the C++ standards.
By the way, 0x3f000000 interpreted as a float is 1.0.
I don't think all implementations represent floating point numbers in the
same way.
I don't know where this random statement about floating point conversions
fits in with the rest of your post. :)
(No, I'm no expert, but I spent some time thinking about ... Paul. These
are some conclusions about my >thoughts, and maybe they're wrong.)

Your thoughts are welcome, Its makes a change from the repetative barrage of
nonsense I have to deal with form the numerous
http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm type
characters on this forum.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top