An array is just a pointer

P

Paul

Nothing wrong with my English.
You were trying to say : "x points to an array" is OK but "x is a pointer
to the array" is completely wrong. You are speaking complete nonsense
because if one is true the other, by definition, is also true.

--You're confusing value and type. The type of x is "pointer to int",
--the value of the pointer to int is address of array element.

The value of a pointer-to an array, is not necessarrilly the address of one
of the pointed-to arrays elements.
Who is confused?

<snip>
 
S

SG

No it's not  the array doesn't change at all, its not converted to anything.

In this instance, you demonstrated that you don't understand the
meaning of the word "conversion" as it is used in the C++ ISO standard
and several posts that mentioned array-to-pointer conversion.
Conversion does NOT imply that the source changes. Conversion is only
about creating something new based on something old. Example:

struct arraylike {
int data[99];
operator int*() {return &(data[0]);}
};

int main() {
arraylike arr;
arr[0] = 1729; // [] works ...
int* ptr = arr; // initialization works ...
// ... because arr is implicitly convertible to an int*
// arr still exists and has not changed at all, though.
}

I have to agree with Alf Steinbach. You are basically wrong about
everything at every conceivable scale. You're clueless and
_not_even_trying_ to understand what people write.

SG
 
P

Paul

cg_chas said:
cg_chas said:
For this particular case, Stroutstup was very clear in his
wording
with
his
series of examples in TCPPPL 5.3 Pointers into Arrays
without
being
ambiguous,
or overly pedantic.

int v[] = {1,2,3,4};
int* p1 =v; //pointer to initial element (implicit
conversion)
int* p2 =&v[0]; //pointer to initial element

++p1; //pointer to 2nd element
++p1; //pointer to 3rd element
++p1; //pointer to 4th element
++p1; //pointer to no elements

p1 is a pointer to the array no matter what element it points
to.

This statement is even less correct than others that you've
made.

Why? becuase you say so?

This isn't about my beliefs or my opinions. I have authoritative
sources
that
state the case clearly in favor of my position and not yours.

Please reveal these secret authorative sources that you claim to
have.

I've already revealed them in this very thread. You're just too
busy
snipping
and "quickscanning" to use your own wording.

All you posted was the folowing:

<quote ref= "your authorative source">
int v[] = {1,2,3,4};
int* p1 =v; //pointer to initial element (implicit conversion)
int* p2 =&v[0]; //pointer to initial element
</quote>

In what way do you interpret this to mean that p1 or p2 are not
pointers
to
an array?
Because it is explicitly stated that p1 and p2 are pointers to a
single
element.
A single element is in fact not the same as an array.
Had the author thought it pertinent to agree with your case, he
would
have
by
now.

If it points to an element in the array then , by definition, it
points
to
the array.

By which C++definition exactly?

Hello? No answer? Should we assume that you do not have a C++
definition
then?
Surely if you know that you are correct like you say you do, then it
would
be
easy to cite the definition that supports you, right? Oh wait, I
forgot,
it
isn't your burden to stand by your words. It's everybody elses.

By the definition .. it points to an array.
That is neither an English language definition nor C++ definition. It is
you
repeating your statement.
What definition do you think stupid.?
That's what I am asking, what C++ definition supports your statement?
You still fail to provide one.

By the way, I laugh at your insults. Instead of answering the question,
you
deflect identically in the way a child would. The difference being of
course is
that a child might actually understand the question.
OK I answered now you answer me.
What does a pointer-to an array point to , if not one of its elements?
You have not answered, you were asked for a C++ definition, yet you
provided
none.

You can't answer because you're just another idiot.

Plonk.
 
P

Paul

On 22 Mrz., 00:33, Paul wrote:
You are not the only one who does not understand arrays. I'm sure
there are many low quality (imprecise and/or wrong) array/pointer
tutorials out there. That's one reason to stick to quality books. You
know... the ones you did not read.
^^that coming form an idiot who obviously doesn't have a clue. ^^
So, a statement as thread title is not a statement anymore.
Do you even listen to yourself?

It's not a statement of fact, as I said.
The fact that you are incapable of understanding a simple statement porves
that you are incappable ofunderstand a complex document such as the C++
standard. Based on this its apparrent the rest of your post is nothing more
than nosensical misinterpretations of the C++ standard.

<snip>
 
P

Paul

Leigh Johnston said:
Lulz; what an immature, stupid, pathetic excuse for a troll you are.
Thats coming from an idiot who uses the term "Lulz". Looks like the language
of a 10 year old girl to me.
*shrug*
 
P

Paul

No it's not the array doesn't change at all, its not converted to
anything.

In this instance, you demonstrated that .....


Does it look like I'm in the slightest bit interested in what you have to
say?

If you dont know the correct termilogy is: "deducing a template argument"
then...
<snip>
 
P

Paul

Leigh Johnston said:
Leigh Johnston said:
On 21/03/2011 23:57, Paul wrote:

It is a 2dim array. How can this not be a pointer to a dynamic array?

int (*pa)[42] = new int[42][42];


Come on?. Tell me how , even in the densest of pea-like brains like
yours, this cannot be a pointer to an array?

You fail yet again. I never said "pa" was not a pointer to an array;
of course it is a pointer to an array; it is a pointer to a 1d array
of type int[42].
It's a pointer to a 2d array
According to you any dynamic array is, not unlike you, 1 dimension short
of a picnic.

int (*pa)[42] = new int[42][42];

"pa" is a pointer to a 1D array of type int[42]; this is an indisputable
fact. The fact that what it points to is the initial element of a 2D
array of type int[42][42] is irrelevant.
It's a pointer to....*drumroll* ..... what it points-to .
You are a confused idiot. Read the standards.
Irrelevant; what is relevant is the type of an object.
I rest my case.

No the correct terminology is "array-to-pointer conversion" as we are
talking about .. wait for it .. array to pointer conversion which is not
restricted to function template template argument deduction.

No we were talking about template sepcializations, which function is called
is based the duduction of the template argument.
No conversion takes place until after the template deduction when, during
invocation of the function, the parameter is converter to a reference, a
pointer, a const ref, a const pointer or whatever type the template
parameter was deduced to be.
 
P

Paul

Leigh Johnston said:
cg_chas said:
For this particular case, Stroutstup was very clear in his
wording
with
his
series of examples in TCPPPL 5.3 Pointers into Arrays
without
being
ambiguous,
or overly pedantic.

int v[] = {1,2,3,4};
int* p1 =v; //pointer to initial element (implicit
conversion)
int* p2 =&v[0]; //pointer to initial element

++p1; //pointer to 2nd element
++p1; //pointer to 3rd element
++p1; //pointer to 4th element
++p1; //pointer to no elements

p1 is a pointer to the array no matter what element it
points
to.

This statement is even less correct than others that you've
made.

Why? becuase you say so?

This isn't about my beliefs or my opinions. I have
authoritative
sources
that
state the case clearly in favor of my position and not yours.

Please reveal these secret authorative sources that you claim
to
have.

I've already revealed them in this very thread. You're just too
busy
snipping
and "quickscanning" to use your own wording.

All you posted was the folowing:

<quote ref= "your authorative source">
int v[] = {1,2,3,4};
int* p1 =v; //pointer to initial element (implicit conversion)
int* p2 =&v[0]; //pointer to initial element
</quote>

In what way do you interpret this to mean that p1 or p2 are not
pointers
to
an array?
Because it is explicitly stated that p1 and p2 are pointers to a
single
element.
A single element is in fact not the same as an array.
Had the author thought it pertinent to agree with your case, he
would
have
by
now.

If it points to an element in the array then , by definition, it
points
to
the array.

By which C++definition exactly?

Hello? No answer? Should we assume that you do not have a C++
definition
then?
Surely if you know that you are correct like you say you do, then it
would
be
easy to cite the definition that supports you, right? Oh wait, I
forgot,
it
isn't your burden to stand by your words. It's everybody elses.


By the definition .. it points to an array.
That is neither an English language definition nor C++ definition. It
is you
repeating your statement.


What definition do you think stupid.?
That's what I am asking, what C++ definition supports your statement?
You still fail to provide one.

By the way, I laugh at your insults. Instead of answering the
question, you
deflect identically in the way a child would. The difference being of
course is
that a child might actually understand the question.


Because if you do not refer to a C++
definition
then we can add this statement to the long list of claims you have
made
without
foundation.

He is specifying to where in the array it points , not that it
doesn't
point
to the array.

In the array and to the array bear only subtle differences in
English,
but
in
C++ they are distinctly different. The addresses stored in the
pointers
p1 and
p2 are addresses of singular integer objects. THAT is by definition.


So what does a pointer-to an array point to , if not one of its
elements?

How about correctly answering the question I asked above before asking
some of
your own that do not even address the example at hand.

OK I answered now you answer me.
What does a pointer-to an array point to , if not one of its elements?
You have not answered, you were asked for a C++ definition, yet you
provided
none.

You can't answer because you're just another idiot.

Plonk.

Do you not see any similarity between you disagreeing on the array/pointer
issue and you disagreeing with the axiom that in C++ a member function is
a member of a class not a member of an object? The fact that in both
cases everyone disagrees with you .....


A few idiots disagree with me, not everyone .

Plonk.
 
P

Paul

Leigh Johnston said:
Leigh Johnston said:
On 22/03/2011 14:32, Paul wrote:

On 21/03/2011 23:57, Paul wrote:

It is a 2dim array. How can this not be a pointer to a dynamic array?

int (*pa)[42] = new int[42][42];


Come on?. Tell me how , even in the densest of pea-like brains like
yours, this cannot be a pointer to an array?

You fail yet again. I never said "pa" was not a pointer to an array;
of course it is a pointer to an array; it is a pointer to a 1d array
of type int[42].

It's a pointer to a 2d array
According to you any dynamic array is, not unlike you, 1 dimension
short
of a picnic.

int (*pa)[42] = new int[42][42];

"pa" is a pointer to a 1D array of type int[42]; this is an
indisputable fact. The fact that what it points to is the initial
element of a 2D array of type int[42][42] is irrelevant.
It's a pointer to....*drumroll* ..... what it points-to .
You are a confused idiot. Read the standards.

Follow your own advice (see below).
The standard states : "If the * operator, either explicitly or implicitly as
a result of subscripting, is applied to this pointer, the result is the
pointedto (n - 1 )dimensional array"
.............
(*pa) produces the **pointedto** (n-1) dimensional array. That is.... if pa
is the **pointedto** 2dim array(which it is) then derefenrencing it should
result in a 1dim array.

std::cout<< typeid(*pa).name(); /*int [42]*/

e voila!
Proven wrong once again.
READ THE STANDARDS.
What case? I see only gibberish coming from you.


The Standard agrees with me and disagrees with you: err no.

"Template argument deduction is done by comparing each function template
Look above ^^^ DEDUCTION ^^^^^^
parameter type (call it P) with
the type of the corresponding argument of the call (call it A) as
described below."
...
"If P is not a reference type:
— If A is an array type, the pointer type produced by the array-to-pointer
standard conversion (4.2) is
used in place of A for type deduction;"
This doesn't say the array is converted to a pointer.
It says the arrays-type is converted to a pointer-type.

The pointer **type** used in produced by the conversion is used in place of
A for type DEDUCTION.

So you are wrong yet again. Read a proper C++ book.

It uses my terminology twice, you are wrong and although maybe capable of
reading, incapable of understanding what you read.
 
H

hanukas

--You're confusing value and type. The type of x is "pointer to int",
--the value of the pointer to int is address of array element.

The value of a pointer-to an array, is not necessarrilly the address of one
of  the pointed-to arrays elements.
Who is confused?

<snip>

You aren't making much sense there, son. You should change your hobby
to something more suited to your unique set of skills.
 
H

hanukas

On 22/03/2011 18:48, Paul wrote:
For this particular case, Stroutstup was very clear in his
wording
with
his
series of examples in TCPPPL 5.3 Pointers into Arrays
without
being
ambiguous,
or overly pedantic.
int v[] = {1,2,3,4};
int* p1 =v; //pointer to initial element (implicit
conversion)
int* p2 =&v[0]; //pointer to initial element
++p1; //pointer to 2nd element
++p1; //pointer to 3rd element
++p1; //pointer to 4th element
++p1; //pointer to no elements
p1 is a pointer to the array no matter what element it
points
to.
This statement is even less correct than others that you've
made.
Why? becuase you say so?
This isn't about my beliefs or my opinions. I have
authoritative
sources
that
state the case clearly in favor of my position and not yours.
Please reveal these secret authorative sources that you claim
to
have.
I've already revealed them in this very thread. You're just too
busy
snipping
and "quickscanning" to use your own wording.
All you posted was the folowing:
<quote ref= "your authorative source">
int v[] = {1,2,3,4};
int* p1 =v; //pointer to initial element (implicit conversion)
int* p2 =&v[0]; //pointer to initial element
</quote>
In what way do you interpret this to mean that p1 or p2 are not
pointers
to
an array?
Because it is explicitly stated that p1 and p2 are pointers to a
single
element.
A single element is in fact not the same as an array.
Had the author thought it pertinent to agree with your case, he
would
have
by
now.
If it points to an element in the array then , by definition, it
points
to
the array.
By which C++definition exactly?
Hello? No answer? Should we assume that you do not have a C++
definition
then?
Surely if you know that you are correct like you say you do, then it
would
be
easy to cite the definition that supports you, right? Oh wait, I
forgot,
it
isn't your burden to stand by your words. It's everybody elses.
By the definition .. it points to an array.
That is neither an English language definition nor C++ definition. It
is you
repeating your statement.
What definition do you think stupid.?
That's what I am asking, what C++ definition supports your statement?
You still fail to provide one.
By the way, I laugh at your insults. Instead of answering the
question, you
deflect identically in the way a child would. The difference being of
course is
that a child might actually understand the question.
Because if you do not refer to a C++
definition
then we can add this statement to the long list of claims you have
made
without
foundation.
He is specifying to where in the array it points , not that it
doesn't
point
to the array.
In the array and to the array bear only subtle differences in
English,
but
in
C++ they are distinctly different. The addresses stored in the
pointers
p1 and
p2 are addresses of singular integer objects. THAT is by definition.
So what does a pointer-to an array point to , if not one of its
elements?
How about correctly answering the question I asked above before asking
some of
your own that do not even address the example at hand.
OK I answered now you answer me.
What does a pointer-to an array point to , if not one of its elements?
You have not answered, you were asked for a C++ definition, yet you
provided
none.
You can't answer because you're just another idiot.
Plonk.
Do you not see any similarity between you disagreeing on the array/pointer
issue and you disagreeing with the axiom that in C++ a member function is
a member of a class not a member of an object?  The fact that in both
cases everyone disagrees with you .....

A few idiots disagree with me, not everyone .

Plonk.

I also think you're wrong.
 
H

hanukas

In this instance, you demonstrated that .....

Does it look like I'm in the slightest bit interested in what you have to
say?

Yes, it does, actually. You just don't have the resources to
understand it. ;)
 
P

Paul

--You're confusing value and type. The type of x is "pointer to int",
--the value of the pointer to int is address of array element.

The value of a pointer-to an array, is not necessarrilly the address of
one
of the pointed-to arrays elements.
Who is confused?

<snip>

--You aren't making much sense there, son. You should change your hobby
--to something more suited to your unique set of skills.

Oviously it's not going to make sense to you, if you don't understand it .
 
P

ptyxs

Le 22/03/2011 10:50, SG a écrit :
James said:
You are being ridicoulous here, the standard is clear about how an array
is implicitly converted to a pointer when subscripted and (*((p)+(i)))
etc, etc, [...]

FYI: There is a difference between "X is Y" and "X is convertible to
Y".

If an array _was_ "just a pointer" (the subject line you've chosen)
there would be no need for such a _conversion_, would there?

Anyhow, you should take your time to read and comprehend what I posted
earlier. In fact, you should make it a habit to think about what
people write some more before you hit the reply button.
jarn
SG
I don't know whether it can help : in Programming : Principles and
nPractise Using C++, 18.5.2, Bjarne Stroustrup says :
"
The name of an array refers to all the elements of the array. Consider :
char ch[100];
The size of ch.sizeof(ch), is 100. However, the name of an array turns
into ("decays to") a pointer with the slightest excuse. For example:
char* p = ch;
Here p is initialized to &ch[10] and sizeof(p) is something like 4 (not
100).
"
I suggest you all to read all of the enlightening 18.5.2 section in
Bjarne Stroustrup book.

There is also a place in his book - I unfortunately couldnt pick up to
copy it here - where he says rougly "better be a good programmer than a
"language lawyer"", a point several writers in the current thread
should perhaps take into account.
 
J

James Kanze

[...]
I'll repeat my suggestion. Read the C++ standard. And show me
where it defines an operator[] on an array.
I'm not wasting my time arguing with you over something that
is utterly and ridiculously obvious.
An array can be indexed. Learn to live with it, its never
gonna change.

Not in C++. (Well, std::array can be indexed.)

[...]
Yes there are planes in any concept of a matrix :)

And there are planes in airports. So. C++ doesn't know
anything about matrices nor airports.
[...]
int* arr1 = new int[12]; /*Create an array of 12 int*/
arr1[0] = 33;
int* arr2 = new(++arr1) int[11]; /*Create an sub-array within
original*/
You see. You even say so: new int[11] creates a new array of 11
ints, and returns a pointer to the first element of that array.
Not a pointer to arr1.
No I said I created an array of 12 ints, then I create and
sub-array within it, which returns a pointer with a value
identical to that of arr1.
You didn't create a subarray. You created a new array, using
some of the memory of the old one. (C++ doesn't have
"subarrays", although I guess you could call an array which is a
subobject of some larger object a subarray. That's not the case
here, however.)
So it's a sub array. :)

No. A sub array would be part of another object. In this case,
you've created a new top level object.
std::cout<< arr2[-1]; /*Access the original array using the
sub-arrays
pointer*/
arr2 doesn't point into the first array; it points into the
array you created with the new expression which you used to
initialized arr2.
arr2 and arr1 both point to the same memory location.
So? The same memory location can be used for different objects
at different times.
I know, I demonstrated doing just that with arr1 and arr2 :)

Except that you're trying to use arr1 (which points into an
object which formally no longer exists) and arr2 in the same
expression. Undefined behavior (formally).

[...]
That's an interesting question, and I don't think that the C++
standard is clear about it. In this case, however, the only
subobjects of an array are its elements. Given your new
(++arr)int[11], if subobjects continue to exist, the first
element of arr is still valid. But the others aren't.
Well the memory is still allocated , so unless random memory
writes are allowed , nothing can take that memory untill I
delete the larger of the two arrays.

But an object is more than just memory, and the standard says
that the object's lifetime ends if the memory is used for
something else.
 
P

Paul

James Kanze said:
[...]
I'll repeat my suggestion. Read the C++ standard. And show me
where it defines an operator[] on an array.
I'm not wasting my time arguing with you over something that
is utterly and ridiculously obvious.
An array can be indexed. Learn to live with it, its never
gonna change.

Not in C++. (Well, std::array can be indexed.)
Yes in C++. AN array can be indexed by subscripting.
Please stop making ridiculous statements that are untrue.

[...]
Yes there are planes in any concept of a matrix :)

And there are planes in airports. So. C++ doesn't know
anything about matrices nor airports.
[...]
int* arr1 = new int[12]; /*Create an array of 12 int*/
arr1[0] = 33;
int* arr2 = new(++arr1) int[11]; /*Create an sub-array within
original*/
You see. You even say so: new int[11] creates a new array of 11
ints, and returns a pointer to the first element of that array.
Not a pointer to arr1.
No I said I created an array of 12 ints, then I create and
sub-array within it, which returns a pointer with a value
identical to that of arr1.
You didn't create a subarray. You created a new array, using
some of the memory of the old one. (C++ doesn't have
"subarrays", although I guess you could call an array which is a
subobject of some larger object a subarray. That's not the case
here, however.)
So it's a sub array. :)

No. A sub array would be part of another object. In this case,
you've created a new top level object.
No I managed the memory in such a way that i created an array within an
existing array.
std::cout<< arr2[-1]; /*Access the original array using the
sub-arrays
pointer*/
arr2 doesn't point into the first array; it points into the
array you created with the new expression which you used to
initialized arr2.
arr2 and arr1 both point to the same memory location.
So? The same memory location can be used for different objects
at different times.
I know, I demonstrated doing just that with arr1 and arr2 :)

Except that you're trying to use arr1 (which points into an
object which formally no longer exists) and arr2 in the same
expression. Undefined behavior (formally).
No I used arr2. they are identical anyway so it wouldn't mater.
[...]
That's an interesting question, and I don't think that the C++
standard is clear about it. In this case, however, the only
subobjects of an array are its elements. Given your new
(++arr)int[11], if subobjects continue to exist, the first
element of arr is still valid. But the others aren't.
Well the memory is still allocated , so unless random memory
writes are allowed , nothing can take that memory untill I
delete the larger of the two arrays.

But an object is more than just memory, and the standard says
that the object's lifetime ends if the memory is used for
something else.
But the whole object wasn't overwritten.
 
J

James Kanze

"James Kanze" <[email protected]> wrote in message
On
"James Kanze" <[email protected]> wrote in message
[...]
I'll repeat my suggestion. Read the C++ standard. And show me
where it defines an operator[] on an array.
I'm not wasting my time arguing with you over something that
is utterly and ridiculously obvious.
An array can be indexed. Learn to live with it, its never
gonna change.
Not in C++. (Well, std::array can be indexed.)
Yes in C++. AN array can be indexed by subscripting.
Please stop making ridiculous statements that are untrue.

Read the standard. The standard explicitly says that the
operands to an [] operator must be a pointer and an integral
type. No array. This has been the case since K&R C, and none
of your claims to the contrary are going to change it.
[...]
[...]
int* arr1 = new int[12]; /*Create an array of 12 int*/
arr1[0] = 33;
int* arr2 = new(++arr1) int[11]; /*Create an sub-array within
original*/
You see. You even say so: new int[11] creates a new array of 11
ints, and returns a pointer to the first element of that array.
Not a pointer to arr1.
No I said I created an array of 12 ints, then I create and
sub-array within it, which returns a pointer with a value
identical to that of arr1.
You didn't create a subarray. You created a new array, using
some of the memory of the old one. (C++ doesn't have
"subarrays", although I guess you could call an array which is a
subobject of some larger object a subarray. That's not the case
here, however.)
So it's a sub array. :)
No. A sub array would be part of another object. In this case,
you've created a new top level object.
No I managed the memory in such a way that i created an array
within an existing array.

Which formally at least causes the previously existing array to
cease to exist. At least according to the standard.

[...]
But the whole object wasn't overwritten.

So you have a (small) part of the previous array? An object
either exists, or it doesn't.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top