P
PaulR
And this is what you'd say to those who think no array object exsitsYes, a single object of array type exists in memory.
We _cannot_ access this single object as a whole. It's as simple as
that.
So what? That's a quirk of the language.
with the expression:
int* p = new int[55];
They say this is just a pointer to a sequence of integer objects, no
array object is created. This may be a valid point because according
to the C++ standard an object of array type is non modifiable and your
definition of an array object is very modifiable.
It's not a matter of seeing a difference, it's a matter of defining
the terms.
If you stipulate that when you say "array type object" you mean
exactly
the same thing as "object of array type", then I'm quite happy to
agree
that, by definition, there _is_ no difference, so I'll _see_ no
difference =)
Yes, that's right. Being very loose with terminology, _all_ variables,
data, what-have-you, are objects. Anything to which you can write, or
from which you can read, a value, is an object. Anything that takes up
measureable memory space is an object. Objects can have subobjects.
So the array is a single object, made up of subobjects.
But we cannot access the array object as a whole, if by "access" you
mean
read the whole thing as a lump.
It just so happens that structs are assignable. But if the language
didn't
support struct assignment, would you say that structs weren't objects?
This seems a bit like a condraction.
You say that loosely spkeaing an object is a region of memory from
which you can either read or write a value.
But then you say an array object is a region of memory that you cannot
read or write to, but its the same region of memory as the integer
objects that can be read or written to.
The same object(region of memory) cannot be accessable yet also
inaccessable (accessable meaning either readable, writeable or both).
A struct is a defintion of a type, you cannot assign to a struct but
you can assign to an object of struct type.
I think this is what you mean and the term "assign to a struct".
Its like saying "assign to a class" huh this is not right, is it?
Yes, it exists. Yes it can be accessed on an element-by-element basis,
just not as one big lump.
Well, yes, they are different objects though not disjoint. The
subobjects
are fully contained within the array object.
They could be seen as the same or different depending on how you look
at it, for example:
The array is the same as the integer objects.
The array is different from a single integer object.
This is because an array can be seen as a sequence of integer objects
or as one single object that contains sub objects.
As I said above the pluralisation is concerned with how you think ofAnd I don't get what you're saying about
the "pluralisation". Yes, there is a single array object containing
multiple subobjects. An int has multiple bits. Does this mean that the
int is different than it's component bits? That's either trivially
true
or trivially false depending on how you interpret it, but either way
it's trivial.
an array.
Is it objects or an object. An array can be seen in both ways.
So the plural objects are accessable and the sigular object is not , isit
just a concept of all the objects grouped together as one?
Its not an object that has been declared or anything, its non modifiable,
its not accessable, a there are different opinions about whether or notit
even exists.Some people say that there is no array object, with dynamic arrays, andthat
an array object is 'arr' in the following:
int arr[55];
This is an array type object because when you examine it with typeid its
type is int[55].
This makes sense because this object is non modifiable. Its also not
accessable, as an object in its own right, because any attempt to access it
yields a pointer to its first element.
That means that your explanation of an array being the collective for all
the elements in memory does not make sense because your explanation of an
array object would also exist with a dynamic array, would it not?
No, the "problem" with dynamic arrays is that there is no identifier
for the
array as a whole. It is anonymous. _All_ we have is a pointer to its
first
element. Since we don't have a name for it, we don't have a way of
identifying
the array-as-a-whole to find its typeid, or size, for that matter.
Again,
this is really just a quirk of the language.
What about this:
int (*p)[16] = (int (*)[16])new int[16];
cout<< sizeof(*p);
cout<< typeid(*p).name();
Does *p give us access to the array object?
Okay, good.
I'm not sure what you mean by "represents the memory". I say that the
array
object simply _is_ that chunk of memory. There may or may not be a
name
identifying that chunk of memory as a whole. There is such a name for
non-dynamic arrays, there is not for dynamics arrays. (Of course, the
name
may not be visible in all scopes, but the point is, it exists
_somewhere_
in the case of non-dynamic arrays.)
A representaton of something is similar to a vector object
representing the array in memory.
For example:
vector<int> v(16);
This creates memory for 16 int objects, and that memory is
represtented by the object 'v'. The object 'v' is not the same as the
16 integer objects that it represents.
This is *similar* to what i mean with an array object representing an
array.
This object is something that the compiler creates as a pointer to the first
element with some additional info that allows the size and typeinfo to be
carried with it.
You say that the compiler "creates [this array object] as a pointer".
I don't
agree, but leave it for a moment. [*]
No I didn't say that at all.
I described a mechanism for implementing an array object based upon a
pointer with addition type info.
I think that in memory no objects exist other than the sequence of element
objects.
However given this C++ type mechanism that allows an identifier to
represent this array as a whole, we can say that the sequence of objects is
one object as a whole.
This is the only way I can see how it works with no conflicting defintions.
The only argument I have seen against this is the "an array is not a
pointer" argument, which is nonsense because I am not saying an array is a
pointer.
[*] But you just said that the array object is "[created] as a
pointer". So it's
created as a pointer, but isn't a pointer? I agree that it isn't a
pointer, but
then what do you mean that it's created "as a pointer".
I was describing a mechanism a compiler could implement to create an
array object.
Going back to a vector object. It will have some allocator that
references the memory location where its elements are stored but this
allocater will eventuall boil down to a pointer somewhere along the
lines. I'm not saying that a vector is a pointer , I am explaining how
it may be implemented.