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 youwant 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 logicallycorrect. 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...
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 did not 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.
Beyond that, you need external information. If you want to be pedantic about it, you could say that all allocations are array allocations justthat many of them are arrays of size 1. Does it change what you can do with >pointers? Nope. Does it change the meaning of pointers? Nope..
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..
I'm not sure what you think Leigh's argument is at this point. I see nothing that contradicts anything Bjarne has ever said. I still contend you are in violent agreement.
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.