P
Paul
On Monday, February 27, 2012 8:07:58 AM UTC-6, Paul wrote:
A 1-dim array doesn't need a multiplier. A 2-dim array doesn't need
two multipliers it only needs one. This is not "loss of information"
as you have put it, the information is not there because it's not
required.
I'm not talking about multipliers, I'm talking about knowing the bounds of the underlying array. It is lost information and it is required if you want to (robustly) treat the pointer as a reference to an array of objects. How do you sensibly increment a pointer without knowing the range of values the pointer can logically take?
An example:
An example:
int a[10];
int (&b)[9] = a[1];
The C++ language dictates that this is illegal syntax, despite the fact that simple analysis shows that it is perfectly reasonable and logically correct. This is the sort of 'context' you've been referring to but this 'context' is exactly what the language does not support.
No I never brought references into the discussion.,
References *are* pointers...But you have said yourself that a pointer does not carry typeinfo. You
are contradicting yourself by saying that a reference is a pointer,
when it suits you.If you insist:
int a[10];
int (*b)[9] =&a[1];
The argument still holds...
Given only
int* iptr = something();
I wish you wouldn't use this default object construction syntax(or
function syntax) when assigning to pointers, because more often than
not this will not return an objects' address. An objects' address is
assigned to a pointer, not an object.
I'm not sure why you'd think it was an object constructor call -- it makes more syntactic sense as a simple function call. In any case, it's pseudo-code. The RHS of the assignment is not relevant which is why I didnot work very hard at making it realistic. The point being: A _naked_ pointer cannot be (usefully) treated as an array reference.
A pointer doesn't only point to an object or null because it can also
point to objects(plural).
It can point to an object allocated as part of an array, yes.No , it can point to objects(plural) , that is what I said objectS
(plural) , not a single object that is part of something.You don't always need information, its a well known fact that in C and
C++ a pointer to an array does not carry size information.
All allocations aren't arrays , because an array is a sequence of
elements. Yes an array of size 1 is the same as a single object but
then that's not really an array is it, its just a single object. And
please don't bring arrays of size 0 into the discussion..Leighs argument is that an int* can only point to a single int and
cannot point to an array of ints. This contradicts what Bjarne says in
his C++ glossary re: "char* - pointer to a char or an array of char"
source:http://www2.research.att.com/~bs/glossary.html.This is why I am objecting to Juha and Leighs argument because they
are confusing the pointers-type with what is pointed-to. The two are
different contexts of "is a pointer -to" and not always related.If we have an object in memory that is an array, of any size: A
pointer to it is a pointer to an array regardless of its's type, or to
where it points within the array. They are incorrect to suggest that
what is pointed to is defined by the pointers type, just look at a
void pointer for an example of how wrong this is.
Your void pointer argument is a straw man. It is really quite simple if
you think in terms of objects: a void* pointer can point to an object of
any type or nothing at all; an int* pointer can point to an object of
type int or nothing at all.
Nope, a pointer can point to an object, objects or nothing.
If an int* pointer points to an object of type int which is part of an
array it is incidental that it is part of an array: it still points to
the array element not the array.
This is plain narrow mindedness.
The way to understand it is that the int* points to int
objects(plural).
The type of objects pointed to are int type objects, thus it's commonWhen talking about C++ types and objects are probably the most important
things to consider.
sense that you'd use an int* to point to them.
Why would you use a pointer of type(*)[10] to point to a 1-dim array
of 10 ints? The extra [10] on this pointer type does nothing to affect
the pointed-to array, it only affects the way its incremented and
indexed. The main thing about this pointer type is that it has another
level of indirection. You cannot index it without an addition
dereference. You cannot increment it with first dereferencing it. It
has an extra level of indirection that is completely unnecessary.