Problem with array objects

P

Paul

This debate has been had before and you cannot accept the obvious.
int* p = new arr[66];

If the allocation succeeds, p points to an array of int objects.
You are of the opinion that p does not point to an array of integers but
only to one single integer.

-- "When the allocated object is an array (that is, the direct-new-
--declarator
-- syntax is used or the new-type-id or type-id denotes an array
--type), the
-- new-expression yields a pointer to the initial element (if any) of
--the array."
-- [Some standard or other, 5.3.4:5]


And you think this means it doesn't point to the array?
If it points to an element (if any) OF THE ARRAY, then it points to the
array.

int* p = new int[1];

This array is sized one so the array is exactly the same thing as its
initial element.
The address of an array is the same as the address of its initial element.
To be specific about what element WITHIN THE ARRAY is pointed to , doesn't
mean the pointer doesn't point to the array.
 
P

Paul

Leigh Johnston said:
Actually I retract that last statement (it is incorrect); I should have
said:

The type of 'p' is fixed and it can only point to objects of a related
type or no object at all;
It does point to objectS of a related type , it points to integer objects.

in this case the only valid related type is 'int' not 'array of int'.
An array of integers type objects is an array of integer types.
An object of array type, is not within the realms of you understanding so no
point in even going there.
 
T

Thomas David Rivers

Paul said:
Consider the following:

void* p1 = (void*)new int;
void* p2 = (void*)new int[55];

p1 points to a single integer.
p2 points to an array of integers.

This is what I mean when I say 'ip' is a pointer to an array. I don't
mean it's type, I am talking about what it points to.

Oh ... uh... I'm not sure how to discuss this.

When you say "I don't mean its type" - do you mean to imply that you are now
no longer talking about/referring to the C/C++ language definition, but
something else?
Because, if we're not talking about the type of a variable, then I'm not
quite
sure what we're talking about, and I think, the language definition is
pretty clear that variables have types and those types are profoundly
meaningful
to the semantic operations of the language.

That is, I'm not sure exactly how to talk about something if we have decided
to throw out the language definition.

I suppose we can introduce new ideas, but, I think, at that point, we're not
talking about C/C++ any more, but something else.... which really isn't
on-topic.
In C++ a pointer type int* can point to:
A single integer or an array of integers.
Null.
Some random uninitialised memory.


I really don't understand that... I'm sorry, but I don't get it.

I believe a statement that conforms with the language definition might be
that a variable of type `int *' can point to an `int'. The value of
that variable
might be any valid address or NULL.

That is, the variable would be a box, and that box can contain the location
of another `int' box, or the 'special' value NULL.

I think that is a characterization that more closely follows the language
definition.
Remember what our definition of an array is. Just a sequence of
objects in memory and nothing more.
If that sequence of objects are int types then the pointer to point to
them must be of type int*.


I'm sorry, but I think I have to disagree with some of that. I do
agree on our
definition of an array.

I think I would say that a pointer to one of the elements of the array would
necessarily be an `int *'. But, in C/C++, it's very easy to construct a
pointer
to the entire array, which is quite different. For example:

int (*ap)[5];

is a pointer to an entire collection of 5 `int' elements. It does not
point to
single element, but an entire collection of 5 `int' elements. It is a
pointer-to-an-array.

The type is very meaningful, and very important, especially in the context
of operations (indexing, for example) on the array.
Also we agreed that 'arr' is a name trhat refers to this array of
objects so with:
int arr[66];
int* p = arr;

p is now a pointer that refers to the same array of integer objects
that 'arr' referred to.

We did agree that 'arr' is a name that refers to the array of objects.

However, we also agreed that in this context, the name 'arr' does not
refer to the entire set of elements.

We agreed that referencing that name in this context did not produce
the array of objects, but instead produced the address of the first element
of the array.

So - in the statement:

int *p = arr;

the 'arr' there does not refer to the entire set of elements - it refers
only
to the address of the first element. I do recall you agreeing with
that... is
that not right?

So - I believe we've been here before, and we agreed that 'p' points to
the first
element of the array. The type of 'p' is clearly an `int *' (pointer
to int), and since
it points to the first element of the array, this is all consistent.

I cannot say 'p' points to the entire array, because that is not its type.

I can say that 'p' points to the first element; I believe that's all the
C/C++
standard and common practice say in this matter.

I can also agree that the starting address of the entire array, and the
starting
address of the first element are the same, since the array is a contiguous
collection of same-typed elements.

Because of this, I might be tempted to say 'p' points to the start of
the array,
which is also true.

But 'p' is not a pointer-to-an-array, it is a pointer-to-int that
happens to be
pointing to the first element of an array of 5 `int' elements.

I believe that would be the terminology that is most accepted and most
closely
matches the language definition.

I had hoped to explain why this is important, by going on to discuss the
indexing
operator and how that relates to pointer arithmetic (which is why
getting the
type correct is critical.)

But, if we cannot agree to stick with the language definition, then it
is going
to be difficult to get a firm understanding of subsequent concepts.

Would you like to continue, using the C/C++ language definitions, or should
we agree to disagree here?

- Dave Rivers -
 
P

Paul

Thomas David Rivers said:
Paul said:
Consider the following:

void* p1 = (void*)new int;
void* p2 = (void*)new int[55];

p1 points to a single integer.
p2 points to an array of integers.

This is what I mean when I say 'ip' is a pointer to an array. I don't
mean it's type, I am talking about what it points to.

Oh ... uh... I'm not sure how to discuss this.

When you say "I don't mean its type" - do you mean to imply that you are
now
no longer talking about/referring to the C/C++ language definition, but
something else?

No not at all.
A pointer is an object that references another location. The term "a pointer
to X" fundamentally means the pointer points to X, whatever X may be.
The type of X is irrelevant because a pointer doesn't point to a type is
points to a memory location.

Having said that, a pointer has a type. This is a completely different
concept from what the pointer points to. A pointer of type pointer to X
doesn't need to point to an X, for example:

X* p =0;

Ok obviously this pointer is null, so points to nothing , but the
declaration that p is of type pointer to X means that p is capable of
addressing an X.
For example an int* cannot address a single char because when derefenced it
will address 4 bytes(on my system) and a char is only 1 byte.
But in the example above p can point to an X or an array of X's because of
the size of memory chucks it addresses, for example:
X* p = new X[100];
++p;

p now points to the 2nd element of the array of X's , but it also still
points to the array of X's. Just because it can point to a single element
does not mean it cannot also be pointing at the whole array, it all depends
on the way the pointer is used and how the programmer treats it. Another
example:

void foo(X* arg, int size){
for (int i=0; i<size; ++i){
arg = i -1; }
}

The above function treats the pointer as an array and it can because the
pointer points to an array.

Yes it does specifically point to one single element at a time but that is
just the nature of how computers address arrays, you cannot address a whole
array at once unless it something silly like size one.


Because, if we're not talking about the type of a variable, then I'm not
quite
sure what we're talking about, and I think, the language definition is
pretty clear that variables have types and those types are profoundly
meaningful
to the semantic operations of the language.
Yes there are types and this is why I was speaking about this non modifiable
object of array type.
We have to introduce this new type to understand how arrays and pointers to
array work in C++.

But what is this object type?
I believe that when we introduce this type we need to redefine exactly what
'arr' is. Is it really just a name that references a simple sequence of
integer objects , or is there more going on under the hood?

That is, I'm not sure exactly how to talk about something if we have
decided
to throw out the language definition.

I suppose we can introduce new ideas, but, I think, at that point, we're
not
talking about C/C++ any more, but something else.... which really isn't
on-topic.
I'm not sure exactly which definiton you speak about here.
I really don't understand that... I'm sorry, but I don't get it.

I believe a statement that conforms with the language definition might be
that a variable of type `int *' can point to an `int'. The value of that
variable
might be any valid address or NULL.

That is, the variable would be a box, and that box can contain the
location
of another `int' box, or the 'special' value NULL.

I think that is a characterization that more closely follows the language
definition.

You keep going on about some language definition, what definition are you
talking about exactly?
Remember what our definition of an array is. Just a sequence of objects
in memory and nothing more.
If that sequence of objects are int types then the pointer to point to
them must be of type int*.


I'm sorry, but I think I have to disagree with some of that. I do agree
on our
definition of an array.

I think I would say that a pointer to one of the elements of the array
would
necessarily be an `int *'. But, in C/C++, it's very easy to construct a
pointer
to the entire array, which is quite different. For example:

int (*ap)[5];

is a pointer to an entire collection of 5 `int' elements. It does not
point to
single element, but an entire collection of 5 `int' elements. It is a
pointer-to-an-array.

Its just a different type of pointer , it points to exactly the same
location.

This pointer type does not point-to anything different form an int*, they
both point to the first element in an array integers. The difference is that
this pointer points to a non modifiable object of array type, when
initiallised with the following:
int arr[5];
int (*p)[5] = &arr;

*p = ??

What does this pointer point to? I have said it is this non modifiable
object of array type, because to me thats what it seem to point to.
Indirectly this pointer points to exactly the same thing as an int* would
point to, that is the first element of the array:
**p = some_int_value;

It points to exactly the same place as an int* would point to but it has an
extra level of indirection.


The type is very meaningful, and very important, especially in the context
of operations (indexing, for example) on the array.
Also we agreed that 'arr' is a name trhat refers to this array of objects
so with:
int arr[66];
int* p = arr;

p is now a pointer that refers to the same array of integer objects that
'arr' referred to.

We did agree that 'arr' is a name that refers to the array of objects.

However, we also agreed that in this context, the name 'arr' does not
refer to the entire set of elements.

We agreed that referencing that name in this context did not produce
the array of objects, but instead produced the address of the first
element
of the array.

So - in the statement:

int *p = arr;

the 'arr' there does not refer to the entire set of elements - it refers
only
to the address of the first element. I do recall you agreeing with
that... is
that not right?

No I doubt I'd have agreed to that, I agree that it points to the first
element but I think it also points to the array.
This is where our differences lie, I believe you think that because it
points to the first element it cannot also point to the array.
So - I believe we've been here before, and we agreed that 'p' points to
the first
element of the array. The type of 'p' is clearly an `int *' (pointer to
int), and since
it points to the first element of the array, this is all consistent.

I cannot say 'p' points to the entire array, because that is not its type.
Its type does not define what is pointed to.

I can say that 'p' points to the first element; I believe that's all the
C/C++
standard and common practice say in this matter.

I can also agree that the starting address of the entire array, and the
starting
address of the first element are the same, since the array is a contiguous
collection of same-typed elements.
Because of this, I might be tempted to say 'p' points to the start of the
array,
which is also true.

Of course its true thats exactly where it points, first and foremost it
points to the beginning of the array. That is the main object it points to.
But 'p' is not a pointer-to-an-array, it is a pointer-to-int that happens
to be
pointing to the first element of an array of 5 `int' elements.

You are confusing pointer types and what is pointed to here.
When you say 'p' is not a pointer-to-an-array what you are meaning is 'p' is
not of type pointer-to-an-array.

It doesn't *just happen* to be pointing to the first element of the array by
some sort of chance, it points primarily to an array of integer objects and
thats why it points to the first element.
It doesn't *just happen* that this integer is the first element of an array.
I believe that would be the terminology that is most accepted and most
closely
matches the language definition.
Well I draw your attention so a couple of quotes from highly regarded
experts who think in the same way as me:
http://c-faq.com/aryptr/aryptr2.html
"The pointer declaration char *p, on the other hand, requests a place which
holds a pointer, to be known by the name ``p''. This pointer can point
almost anywhere: to any char, or to any contiguous array of chars, or
nowhere [footnote]"

http://www2.research.att.com/~bs/glossary.html
"char* - pointer to a char or an array of char. Typically assumed to point
to a C-style string. Prefer a standard library string over a C-style string
when you can. TC++PL 2.3.3, 13.5.2. "
I had hoped to explain why this is important, by going on to discuss the
indexing
operator and how that relates to pointer arithmetic (which is why getting
the
type correct is critical.)
But, if we cannot agree to stick with the language definition, then it is
going
to be difficult to get a firm understanding of subsequent concepts.

Would you like to continue, using the C/C++ language definitions, or
should
we agree to disagree here?

Well I don't know what definitons you are speaking about.
As far as I can tell, the way I see arrays and pointers is the correct way ,
and it never did me any harm. If the C++ standard has some definiton that
suggests a pointer of type pointer-to-X can only ever point to a single X
object and nothing else then I would probably ignore the C++ standard and
carry on with the opinion that the comittee had all become brian dead
idiots, TBH :)
 
P

Paul

Leigh Johnston said:
On 01/06/2011 15:53, Paul wrote:

[snip]
Consider the following:

void* p1 = (void*)new int;
void* p2 = (void*)new int[55];

p1 points to a single integer.
p2 points to an array of integers.

Wrong; p2 points to the initial element of the array of integers; the
Standard is quite clear as to what new[] returns:

5.3.4/2
"If it is an array, the new-expression
returns a pointer to the initial element of the array."
Saying that a pointer points to the first element of an array, implies what
is pointed to is an array of objects, not one single object. You are taking
some narrow minded view by suggesting it does not point to the array, it
points to the first element of the array.

An array can be seen as nothing more than a sequence of objects of the same
type , or it can be seen as some more complex non modifiable object of array
type.
When referring to a pointer to an array , you chose the latter meaning of
'array' as the only correct interpretation because it suits your argument.

Lets say we have a Domino object, kinda like a tuple, call it a D type.
D* arr[28];
D* dominos =arr;

dominos points to the initial domino in the set. But it can also point to
all dominos in the set:
dominos[0];
dominos[1];
dominos[2];
etc,etc.

By adding an index(or an offset) we can use this pointer to point to any
domino in the set.
This pointer can only point to one domino at a time , but it can point to
any of the dominos in the set.

It is regarded as a pointer to the set of dominos, not a pointer to one
single domino.
 
P

Paul

Leigh Johnston said:
Wrong; a pointer can never point to more than one object; a pointer can
only ever point to a single object; a pointer of type 'int*' can only
point to a single 'int' object not an array of 'int' objects.
No I suggest that its you who is wrong.

A pointer is something that references another location. What a pointer
points to is what is at the referenced location.
If a pointer references a location where an array of objects are stored,
then the pointer is said to "point to" the array of objects, not only to one
single object. The pointer can only access one object at a time , so one can
say specifically which object within the array is pointed to, most commonly
the initial element, but this does not mean the pointer does not still
primarily point to an array of objects.
 
P

Paul

Leigh Johnston said:
[snip]
I believe that would be the terminology that is most accepted and most
closely
matches the language definition.
Well I draw your attention so a couple of quotes from highly regarded
experts who think in the same way as me:
http://c-faq.com/aryptr/aryptr2.html
"The pointer declaration char *p, on the other hand, requests a place
which holds a pointer, to be known by the name ``p''. This pointer can
point almost anywhere: to any char, or to any contiguous array of chars,
or nowhere [footnote]"

http://www2.research.att.com/~bs/glossary.html
"char* - pointer to a char or an array of char. Typically assumed to
point to a C-style string. Prefer a standard library string over a
C-style string when you can. TC++PL 2.3.3, 13.5.2. "

Appealing to authority is a logical fallacy; you have been told this
before; try paying attention.
I don't know what you mean by "appealing to authority" because I am not
appealing to anyone.
I was simply showing that the terminology I use is also used by respected
experts.
'char*' cannot point to an array of char; 'char*' can only ever point to a
single char object (or no object at all):

Perhaps you do know C++ better than Bjarne Stroustrup or Steve Summit,
perhaps you don't.

Whatever the case may be I prefer to think that a pointer that points to an
array of chars is of type char*. Having said that I also fully understand
that there can be a pointer type char (*)[n], but I see that as a pointer
with a different level of indirection that is most commonly used as a
pointer to a 2d array because it requires two dereferences to access the
array of chars that it points to.
 
P

Paul

A. Bolmarcich said:
A. Bolmarcich said:
On 2011-05-28, Paul <[email protected]> wrote:
[snip]
Section 8.3.4 Arrays

5 [ Note: conversions affecting expressions of array type are described
in
4.2. Objects of array types cannot be modified, see 3.10. -end note ]
§
[snip]
The sections of the C++ standard cited in the above note give the
details of why assigning to an array type is not allowed. Paragraph
1 of section 4.2 (Array-to-pointer conversion) is:

An lvalue or rvalue of type "array of N T" or "array of unknown
bound of T" can be converted to an rvalue of type "pointer to T."
The result is a pointer to the first element of the array.

Note that the result of an array-to-pointer conversion is an rvalue
of type pointer.

The first two paragraphs of 3.10 (Lvalues and rvalues) are

Every expression is either an lvalue or an rvalue.

An lvalue refers to an object or function. Some rvalue expressions
--- those of class or cv-qualified class type --- also refer to
objects.

Given the declaration

int z;

the result of the expression z is an lvalue that refers to the object
where the value of the variable z is stored.

Because a pointer is not of a class or cv-qualified class type, the
rvalue result of array-to-pointer conversion does not refer to an
object. In a assignment the left operand needs to refer to an object,
the one whose value is replaced with that of the right operand of the
assignment.
What did you have for breakfast?

What I had for breakfast is irrelevant.
A pointer is not a class , period.

I never stated it was. I wrote: "Because a pointer is not of a
class or cv-qualified class type, the rvalue result of
array-to-pointer conversion does not refer to an object." The "of
class or cv-qualified class type" part is from the C++ standard about
rvalues that refer to objects. I simply reasoned from statements in
the C++ standard to reach a conclusion about details behind why
assigning to an array type is not allowed.

So the rvalue result of an array to pointer conversion does not refer to an
object?
Well what does it refer to? And what does it mean by "refer to", does this
mean the same as what it "points to"?

I think you are getting to tied up with language lawyeresque. You cannot see
the the wood for the trees.
 
T

Thomas David Rivers

Paul said:
Well I don't know what definitons you are speaking about.
As far as I can tell, the way I see arrays and pointers is the correct
way , and it never did me any harm. If the C++ standard has some
definiton that suggests a pointer of type pointer-to-X can only ever
point to a single X object and nothing else then I would probably
ignore the C++ standard and carry on with the opinion that the
comittee had all become brian dead idiots, TBH :)

Oh, I'm disappointed to read that. I was hoping we could come to an
understanding that was rooted in the C/C++ language definitions (the
standard
documents) but I suppose I'm not able to explain things in a manner that you
agree with.

I'm afraid I will just have to drop things here.

I wish you the best of luck in everything you do.

- Dave Rivers -
 
I

Ian Collins

Oh, I'm disappointed to read that. I was hoping we could come to an
understanding that was rooted in the C/C++ language definitions (the
standard
documents) but I suppose I'm not able to explain things in a manner that you
agree with.

Don't worry, no one else can either.

Yours was a detailed and patient attempt and I'm sure those willing to
learn would have learned a great deal form your postings.
 
P

Paul

Pete Becker said:
No, an int* cannot point to an array of ints. They have different types.
An int* points to an int. That int can be an element of an array (or even
one past the end of an array).

--

An array of integer objects is a sequence of objects of int type. A pointer
that points to them is of type int*.
Where do you see the difference in type, other than one is a pointer type
and the other not?

For example:
int* p = new int[100];
p[56];
p[32];

The pointer p points to the array of integer objects. An index(or offset) is
added to the pointer to access different parts of the array.
 
P

Paul

Thomas David Rivers said:
Oh, I'm disappointed to read that. I was hoping we could come to an
understanding that was rooted in the C/C++ language definitions (the
standard
documents) but I suppose I'm not able to explain things in a manner that
you
agree with.

I'm afraid I will just have to drop things here.

I wish you the best of luck in everything you do.
Ok np .
We can agree to disagree.
But I would still like to know what defintions you refer to.
Please can you quote the defintion from the standard you are referring to.
I cannot find any defintions that suggest a pointer of type T cannot point
to more than one T. In fact I cannot even finds a defintion of a pointer in
the C++ standards however I can in the C standards, but i don't know if the
C standard is embraced into the C++ standard as part of the fundamental
rules.
 
P

Paul

Ian Collins said:
Don't worry, no one else can either.

Yours was a detailed and patient attempt and I'm sure those willing to
learn would have learned a great deal form your postings.

I'm sure Thomas is a very knowledgeable programmer , in fact he must be if
he has written compilers and stuff.
One thing about Thomas' debate is that he did not put himself across as
definately correct and anyone who disagreed with him to be incorrect.
I was allowed to disagree with him without being incorrect.



There is a problem with inconsistency in the terminology used the C++
standards. For example the word "contains" .
(1) An object of array type, which nobody around can even acknowledge , is
described as some object that "contains" sub objects of element types.
I can understand this *concept* sure but there is no physical object in
memory that contains sub-objects.

(2) An object(of class type) does not contain member functions. LOL
This must be a joke because an array object can "contain" sub objects , as a
concept but an object(of class type) cannot "contain" memeber function, as a
concept.


The problem is that people can interpret the standards in different ways,
and when the majority of people in a given group come to a consensus about
the interpreted meaning, that is the defined meaning.
But a technical standard should define what it is written to define , not a
clique of people who have a common concencus of its interpretation.
 
T

Thomas David Rivers

Paul said:
Ok np .
We can agree to disagree.
But I would still like to know what defintions you refer to.
Please can you quote the defintion from the standard you are referring
to.
I cannot find any defintions that suggest a pointer of type T cannot
point to more than one T. In fact I cannot even finds a defintion of a
pointer in the C++ standards however I can in the C standards, but i
don't know if the C standard is embraced into the C++ standard as part
of the fundamental rules.
The definition of a pointer can be found in section 8.3.1 on page 131 of
the 1998
C++ standard (ISO/IEC 14882:1998(E)).

Appendix C of that same standard discusses compatibility between
the C and C++ languages. Section C.1 the relationship between the
programming
languages, section C.2 provides something similar for the C runtime library.


- Dave Rivers -
 
P

Paul

Leigh Johnston said:
Leigh Johnston said:
On 01/06/2011 15:53, Paul wrote:

[snip]

Consider the following:

void* p1 = (void*)new int;
void* p2 = (void*)new int[55];

p1 points to a single integer.
p2 points to an array of integers.


Wrong; p2 points to the initial element of the array of integers; the
Standard is quite clear as to what new[] returns:

5.3.4/2
"If it is an array, the new-expression
returns a pointer to the initial element of the array."
Saying that a pointer points to the first element of an array, implies
what is pointed to is an array of objects, not one single object. You
are taking some narrow minded view by suggesting it does not point to
the array, it points to the first element of the array.

Wrong; the first element of an array is a single object. My view is not
narrow minded as my view is backed up by the Standard (which is an appeal
to authority, yes, but the Standard is the ultimate authority as far as
this newsgroup is concerned).

The pointer points to a location, the location it points to is both the
location of the first element and the beginning of the array.

What exactly is the definiton of a pointer in C++. As far as I can see a
pointer is not defined the C++ standard but it is defined in the C standard.
I don't know if the C standard is to be referred to if we need the
definition of a pointer, do you know ?
An array is an object which contains 1 or more contiguous sub-objects of
the same type. The fact that an array object is non-modifiable is not
relevant to this discussion.
This is just going around in circles , you are speaking about an array as
being a non modifiable object of array type.

You idea of a pointer to an array becomes a mess when you consider 2d
arrays.
A 2d array is an array of array-type objects. So you'd need a pointer of
type :
int (*p)[n][n];
To point to a 2d array, and this is not the way things are described in the
standard.

A pointer to an array is a pointer to an object of array type yes; what is
your point?

But you refuse to accept that a pointer of type int* can point to an array
of int objects.

Do you not see the difference between:
(a) Pointer to integer objects
(b) Pointer to an object of array type.


Lets say we have a Domino object, kinda like a tuple, call it a D type.
D* arr[28];
D* dominos =arr;

That is an error; 'arr' and 'dominos' are unrelated types.
Yes correct I made a type it sohuld've been:
D arr[28];
But then that is pretty obviously a simple typo.
dominos points to the initial domino in the set. But it can also point
to all dominos in the set:
dominos[0];
dominos[1];
dominos[2];
etc,etc.

By adding an index(or an offset) we can use this pointer to point to any
domino in the set.
This pointer can only point to one domino at a time , but it can point
to any of the dominos in the set.

It is regarded as a pointer to the set of dominos, not a pointer to one
single domino.

Whether it is bananas, strawberries or dominoes it makes no difference to
that fact that a pointer of type 'foo*' can only point to objects of type
'foo' (or objects of a type related to 'foo'); it cannot point to objects
of type array of 'foo'.
But you contradict yourself because you say that a pointer of type foo* can
point to objectS(NOTE THE FUCKIN PLURAL) of the foo.
Yet you do not accept that a foo* can actually point to objects of type foo
and you'll say in another statement that it can only point to one single foo
 
P

Paul

Leigh Johnston said:
[snip]

I believe that would be the terminology that is most accepted and most
closely
matches the language definition.

Well I draw your attention so a couple of quotes from highly regarded
experts who think in the same way as me:
http://c-faq.com/aryptr/aryptr2.html
"The pointer declaration char *p, on the other hand, requests a place
which holds a pointer, to be known by the name ``p''. This pointer can
point almost anywhere: to any char, or to any contiguous array of
chars,
or nowhere [footnote]"

http://www2.research.att.com/~bs/glossary.html
"char* - pointer to a char or an array of char. Typically assumed to
point to a C-style string. Prefer a standard library string over a
C-style string when you can. TC++PL 2.3.3, 13.5.2. "

Appealing to authority is a logical fallacy; you have been told this
before; try paying attention.
I don't know what you mean by "appealing to authority" because I am not
appealing to anyone.
http://en.wikipedia.org/wiki/Appeal_to_authority

I was simply showing that the terminology I use is also used by
respected experts.
http://en.wikipedia.org/wiki/Appeal_to_authority
'char*' cannot point to an array of char; 'char*' can only ever point
to a single char object (or no object at all):

Perhaps you do know C++ better than Bjarne Stroustrup or Steve Summit,
perhaps you don't.

What has Bjarne Stroustrup knowing C++ better than me got to do with
anything? We all make mistakes; we all sometimes write something which is
less formal or less technically accurate than it should be; you certainly
are.
Who are you to say they are technically inaccurate?
The C faqs are easily ammended, if SS is technically inaccurate then he
would have corrected it by now.
BS's site was modified in 2007, I'm sure he has revised this site and would
have corrected any technically inaccurate information.

I'm sure both these sites have been scrutinised by many programmers and any
inaccuracies would be corrected. They don't just throw these pages online
without first checking them for technical accuracy.

Whatever the case may be I prefer to think that a pointer that points to
an array of chars is of type char*. Having said that I also fully
understand that there can be a pointer type char (*)[n], but I see that
as a pointer with a different level of indirection that is most commonly
used as a pointer to a 2d array because it requires two dereferences to
access the array of chars that it points to.

'char(*)[n]' is a pointer to a 1D array not a pointer to a 2D array; the
first dereference evaluates to a reference to the array and the second
dereference evaluates to a reference to the array element.
The C++ standard states that a when a 2d array is converted to a
pointer....:
"If the * operator, either explicitly or implicitly as a result of
subscripting, is applied to this pointer, the result is the pointed-to (n ?
1)-dimensional array, which itself is immediately converted into a pointer."

The key phrase here is "the pointed-to (n ? 1)-dimensional array". This
means the pointed-to (n)-dimensional array is a 2d array because the
resulting (n-1)-dimensional array is a 1d array.

So your interpretation means that not only are Bjarne Stroustrup and Steve
Summit technically inaccurate but the C++ standard is completely incorrect.

Im sorry but I do not agree with you.
 
P

Paul

Pete Becker said:
I look forward to seeing your rewrite of the C++ standard with all the
problems you perceive fixed so that no reader could possibly interpret it
differently from what you intended. When will it be available?
There is no need for this sarcasm, I fully appreciate the mammoth task of
creating the C++ standard.

But you cannot have it both ways, you want an array to be a non modifiable
object of array type when we discuss pointers to arrays, but in other
situations you want an array to be a sequence of objects.
Also this object of array type is not clearly defined in the C++ standards.
What exactly is this non modifiable object of array type, is it an object or
is it a type?

If its an object then , as defined in the standards, an object is a region
of storage, so where is this object stored? It cannot be stored int he same
region as its elements because that region of storage is modifiable.

If its a type then you are saying that a pointer points to a type. Then this
does not agree wtih , what I think is the generally accepted definiton of
what is "pointed to", because a pointer points to an object(or a location)
not a type.
 
P

Paul

Thomas David Rivers said:
The definition of a pointer can be found in section 8.3.1 on page 131 of
the 1998
C++ standard (ISO/IEC 14882:1998(E)).

Appendix C of that same standard discusses compatibility between
the C and C++ languages. Section C.1 the relationship between the
programming
languages, section C.2 provides something similar for the C runtime
library.
I have only access to the draft 0xx standard ATM but I think its probably
the same for these chapters.
From appendix C and also from section 1.1 para 2 it seems that the C++
standard does seem to treat the C standard as a basic foundation on which
the C++ standard is built, do you agree?
 
I

Ian Collins

If its an object then , as defined in the standards, an object is a region
of storage, so where is this object stored? It cannot be stored int he same
region as its elements because that region of storage is modifiable.

Consider:

struct X { mutable int n; };

int main()
{
const X x1 = {0};
X x2 = {1};

x1 = x2; // Error, x1 isn't modifiable.
x1.n = x2.n; // OK, x1.n is.
}

Are there two instances of x1?
 
P

Paul

Pete Becker said:
An array of integer objects is a sequence of objects of int type. A
pointer that points to them is of type int*.
Where do you see the difference in type, other than one is a pointer type
and the other not?

int *ip; // pointer to int
int arr[10]; // array of int

These are not the same type. Look it up.

No obviously not but neither is:
int x;
int* p =&x;

These two are not the same type either but p points to x.

For example:
int* p = new int[100];

Creates an object of type array of 100 int, converts it to type int*, and
stores the result in p.

Ok this is interesting, so an object of array type is created but its must
be a temporary.
Is it possible to get hold of this array type object( object of array type)
by this syntax:

int (*p)[100] = (int (*)[100])new int[100];

Does this now mean that we have access to the array type object( object of
array type?
Is it the case that an array type object is created , then converted to an
int*, then cast to a pointer to an array type object?


Do you think an object of array type is the same as an array type object?
Just to save me from clarifying my meaning(in brackets) all the time?
 

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,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top