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.)
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.)