Problem with array objects

P

Paul

After recent discussions I have come to the following conclusion:

"A pointer-to an array-type object" is not the same as "a pointer to an
array of objects" . Example:

int array[16];
int (*p_arraytype object)[16] = &array; /*(1)*/
int* p_array_of_objects = array; /*(2)*/

More generally the following terms can be used:
1) pointer to an array-type
2) pointer to an array

There are many confused individuals who say "pointer to array", when they
mean "pointer to array-type object". Often they put their opinions across in
such a way that it's a factual statement of an expert, perhaps because they
believe they are experts. As this newsgroup is unmoderated there is no way
to stop an overwhelming flow of bullshit from these self proclaimed experts,
so I would like to advise any beginners to use their brain and understand
how things work, and not to listen to these people with deluded opinions.

Hope this helps to clear up any confusion introduced in my other threads.

TY
Paul.
 
C

crea

cg_chas said:
and my personal favorite, "an array is just
a pointer".

Its not just a pointer. Array is a ordered (0,1,2 ...) group data item
(basically any type). Yes, array has a pointer -- to pointing to its first
item and to know where its located in the memory.

So I would say: Array consists of pointer which tells where the array is
located and the content of memory blocks to define the items.

I just made it from my head, but I think this is correct.
 
P

Paul

cg_chas said:
After recent discussions I have come to the following conclusion: priceless.


"A pointer-to an array-type object" is not the same as "a pointer to an
array of objects" . Example:
And nobody has argued this point that I am aware of. Nevertheless,
congratulations on your epiphany.
int array[16];
int (*p_arraytype object)[16] = &array; /*(1)*/
int* p_array_of_objects = array; /*(2)*/

More generally the following terms can be used:
1) pointer to an array-type
2) pointer to an array
Sure if you have no regard for technical correctness, but if you do then:
1) pointer to an array of 16 integers
2) pointer to an integer
Your terminology is confusing and could easily be mistaken for:
int* p_arr = new int[16];
int x;
int p_int = &x;

You terminology is certainly not more technical correct than the terminology
i used. You are just one of those confused self proclaimed experts I was
talking about.


but don't take my word for it..

"The C++ Programming Language section 5.1"
For a type T, T* is the type "pointer to T". That is, a variable of type
T*
holds the address of type T.

Use Bjarne Stroustrup terms and stop attempting to sway the community into
thinking your epiphany has any value to anyone else.
Bjarne agrees with me, that is a pointer of type T points to an object of
type T, or an array of objects of type T.

You seem to suggest Bjarne is saying that pointer to type T cannot also
point to an array of objects of type T, which ofcourse makes you totally
confused, and rather stupid in the eyes of most people I would think.


LOL, it is called citing an authoritative source!
You should try it some time, it does wonders for your credibility.
Not much point in citing an autohorative source if you are misinterpreting
him

<snip>
 
C

crea

Leigh said:
An array does not consist of a pointer; an array is convertible to a
pointer.

in c++ sense it does. How do you otherwise know where the data is located if
there is no pointer? You have to know the address of the first item
otherwise the array is useless.
 
C

crea

Leigh said:
An array does not consist of a pointer; an array is convertible to a
pointer.

Yes, array likeÖ
int arr[10];

then arr is NOT a pointer. Thats true. But still, arr must contain the
address of [0]. Ok , the word "pointer" is not precise, but "address" is.
So:
array is:
- address of the array
- ordered items
 
P

Paul

crea said:
Its not just a pointer. Array is a ordered (0,1,2 ...) group data item
(basically any type). Yes, array has a pointer -- to pointing to its first
item and to know where its located in the memory.

So I would say: Array consists of pointer which tells where the array is
located and the content of memory blocks to define the items.

I just made it from my head, but I think this is correct.
More or less but I don't think the term "ordered" group is appropriate.

There is a good article about it here, its all explained well, IMO.:
http://c-faq.com/aryptr/aryptr2.html
 
P

Paul

crea said:
Leigh said:
An array does not consist of a pointer; an array is convertible to a
pointer.

Yes, array likeÖ
int arr[10];

then arr is NOT a pointer. Thats true. But still, arr must contain the
address of [0]. Ok , the word "pointer" is not precise, but "address" is.
So:
array is:
- address of the array
- ordered items
Glad you noticed , this is exactlty what I was explaing about these people
not understand the difference between:
1) An array, or an array of objects of type T
2) An array-object.

An array-object *is like* a const pointer to the array, with additional type
info
 
P

Paul

Leigh Johnston said:
In C++ an array is not a pointer nor does it "consist" of a pointer; you
do not need a pointer to determine the address of the initial array
element of an array on the stack for example. Whilst an array is
convertible to a pointer (which is probably the source of your confusion)
it is wrong to say that an array "consists" of a pointer as technical
accuracy is quite important (something Paul The Troll doesn't get).

Leigh please stop acting like you are an authorative source, I would like to
remind you of the previous thread ref: "you snipped something".

WHere it is apparrent you are a complete idiot who doens't know what you're
talking about.
 
S

SG

An array-object *is like* a const pointer to the array,
with additional type info

Translation: "I was wrong to say 'an array is just a pointer'."

I suppose this is a way of thinking you might end up adopting if you
learn C or C++ by trial-and-error and without any decent books that
teach you the right mental models and terminology.

Another one is: an array-object is an array-object (containing all
elements as subobjects). It is implicitly convertible to a pointer to
its first element (array-to-pointer standard conversion) just like an
int value is implicitly convertible to a double value. This is the way
of thinking the C++ ISO standard suggests and this way of thinking
allows you to avoid the rather magical/vague "with additional type
info" part.

You might want to check again (ISO 14882) clause 3 (basic concepts), 4
(standard conversions), 5 (expressions), and 17.8.2 (template argument
deduction) -- since you came up with a function template for proving
that "an array is just a pointer".

You're welcome.

SG
 
P

Paul

SG said:
Translation: "I was wrong to say 'an array is just a pointer'."

Fortunately for me my text does not need any "translations". The only people
wrong here are the likes of you who think that an int* cannot point to an
array of ints.
I suppose this is a way of thinking you might end up adopting if you
learn C or C++ by trial-and-error and without any decent books that
teach you the right mental models and terminology.
Your philosophy on peoples ways of thinking is, similar to your
understanding of C++, nothing more than utter bollocks TBH.
Another one is: an array-object is an array-object (containing all
elements as subobjects). It is implicitly convertible to a pointer to
its first element (array-to-pointer standard conversion) just like an
int value is implicitly convertible to a double value. This is the way
of thinking the C++ ISO standard suggests and this way of thinking
allows you to avoid the rather magical/vague "with additional type
info" part.

You might want to check again (ISO 14882) clause 3 (basic concepts), 4
(standard conversions), 5 (expressions), and 17.8.2 (template argument
deduction) -- since you came up with a function template for proving
that "an array is just a pointer".
Yeah yeah , make a bunch of random references to the C++ standard and you
must be an authorative figure, seem it all before you obviously don't have
a clue what you are talking about.
 
J

Joel C. Salomon

crea said:
So I would say: Array consists of pointer which tells where the array is
located and the content of memory blocks to define the items.

I just made it from my head, but I think this is correct.

Um... That's not your head you're pointing to.

--Joel
 
J

Joel C. Salomon

Paul said:
After recent discussions I have come to the following conclusion:

"A pointer-to an array-type object" is not the same as "a pointer to an
array of objects" . Example:

int array[16];
int (*p_arraytype object)[16] = &array; /*(1)*/
int* p_array_of_objects = array; /*(2)*/

More generally the following terms can be used:
1) pointer to an array-type
2) pointer to an array

There are many ... individuals who say "pointer to array", when they
mean "pointer to array-type object".

We can avoid some more confusion if we eschew the term "pointer to array"
entirely, and instead say "pointer into an array". Consider:

int i, a[16];
int *p0 = &i; /* pointer to int object */
int *p1 = &a[0]; /* pointer to int = pointer *into* int array */
int *p2 = a; /* shortcut for the above */
int (*pa)[16] = &a; /* pointer to array object */

where I use the term "pointer to array object" for what you called "pointer
to array-type".
Hope this helps to clear up any confusion introduced in my other threads.

I hope so too.

--Joel
 
P

Paul

Joel C. Salomon said:
Paul said:
After recent discussions I have come to the following conclusion:

"A pointer-to an array-type object" is not the same as "a pointer to an
array of objects" . Example:

int array[16];
int (*p_arraytype object)[16] = &array; /*(1)*/
int* p_array_of_objects = array; /*(2)*/

More generally the following terms can be used:
1) pointer to an array-type
2) pointer to an array

There are many ... individuals who say "pointer to array", when they mean
"pointer to array-type object".

We can avoid some more confusion if we eschew the term "pointer to array"
entirely, and instead say "pointer into an array". Consider:

int i, a[16];
int *p0 = &i; /* pointer to int object */
int *p1 = &a[0]; /* pointer to int = pointer *into* int array */
int *p2 = a; /* shortcut for the above */
int (*pa)[16] = &a; /* pointer to array object */

where I use the term "pointer to array object" for what you called
"pointer
to array-type".
This is erroneous, because "pointer to array object" can be either:
int* p1 = new int[dim]; /* p1 points to a 1dim array of type int */
int (*p2)[dim2] = new int[dim1][dim2]; /*p2 points to a 2dim array of type
int */
int arr[5] = {1,2,3,4,5};
int (*p3)[dim] = &arr; /*Pointless extra level of indirection [see note]*/
int** p4 = &arr; /*Same as above, but without typeinfo*/
int x = **p3; /*Same as (**p4) */
int* p5 = *p3; /* p5 is a pointer to an array(of objects) of type int */

This is the source of much confusion because many people cannot accept that
a pointer to an array *can* point to both a single element and the array, at
the same time. I emphasise 'can' because a pointer to an array does not need
to point to an element, its allowed to point one past the last element.

I used the analogy before about pointing to a bunch of bananas. If you point
to a banana within a bunch you are also pointing at the bunch of bananas.

Note:: there may be some rare circumstances where this is of reasonable use.

HTH
Paul.
 
S

SG

This is the source of much confusion because many people cannot accept
that a pointer to an array *can* point to both a single element and
the array, at the same time.

They cannot accept that because their mental model about arrays,
objects, and pointers does not let them. Their idea of a pointer is
something that points to exactly one thing and one thing only unless
it's a null pointer or a one-past-the-end pointer. And to what kind of
objects their pointers point to is statically controlled by the type
of the pointer. It's a different way of thinking about these things
that is more focused on types and that does not match your way of
thinking. I get that. You don't.
I used the analogy before about pointing to a bunch of bananas.

....which has been pointed out to be a flawed analogy given their
mental model about arrays, pointers and objects. It's an analogy that
only fits using your way of thinking.

Fortunately for me my text does not need any "translations".

From what I can tell, your texts need lots of translation and
clarification. That's because you seemingly tend to express your
thoughts on C++ related matters using a different understanding of the
words' meanings. Examples include "pointer to array" as well as "being
part of an object".

In addition you're stating things as fact which are plain wrong.
Examples include "an array is just a pointer". You recently refined
that to be "An array-object *is like* a const pointer to the array,
with additional type info". That's better, I guess. But not much
better. The _precise_ version of this can be found in the C++ ISO
standard:

ISO 14882, §4.2 [array.conv]
----------------------------
"An [expression] 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."

This conversion is again referenced in §17.8.2 when it's about
template argument deduction. You can look it up yourself.
Your philosophy on peoples ways of thinking is
[...] nothing more than utter bollocks TBH.

I think you say this because you don't understand what I am talking
about. I think you adopted your way of thinking about arrays and
pointers because you learned C and/or C++ mainly by trial-and-error
and came up with this mental model as explanation for the behaviour
you observed.
Yeah yeah, make a bunch of random references to the C++ standard and you
must be an authorative figure, seem it all before you obviously don't have
a clue what you are talking about.

I make these broad references because you don't seem to have a firm
grasp on C++ concepts and terminology (as can be found in the ISO
standard). For example, §3 explains to you what lvalues and rvalues
are about. It links lvalues and rvalues to expressions. Something you
should be aware of when reading the following clauses. Clause §4
explains standard conversions, including array-to-pointer conversion.
§5 explains what expressions are about including what the type of an
id-expression is that names a reference, for example. §17.8.2 explains
the rules of template argument deduction including the one that
explains the behaviour of your code examples with a function template
'foo' you presented in order to "prove" that "arrays are just
pointers". However, the observable behaviour of your test programs
does not contradict with the mental model of your "opponents". The
fact that you believe otherwise just suggests that you don't
understand what people are talking about.

SG
 
P

Paul

cg_chas said:
cg_chas said:
After recent discussions I have come to the following conclusion:
priceless.


"A pointer-to an array-type object" is not the same as "a pointer to an
array of objects" . Example:
And nobody has argued this point that I am aware of. Nevertheless,
congratulations on your epiphany.


int array[16];
int (*p_arraytype object)[16] = &array; /*(1)*/
int* p_array_of_objects = array; /*(2)*/

More generally the following terms can be used:
1) pointer to an array-type
2) pointer to an array
Sure if you have no regard for technical correctness, but if you do
then:
1) pointer to an array of 16 integers
2) pointer to an integer
Your terminology is confusing and could easily be mistaken for:
int* p_arr = new int[16];
int x;
int p_int = &x;

You terminology is certainly not more technical correct than the
terminology
i used. You are just one of those confused self proclaimed experts I was
talking about.
The terminology I use is technically correct, not because I say so, but
because
it closely follows that of the author of the C++ language. As I said,
"Don't
take my word for it."

No it doesn't you suggest that the following is not a pointer to an array
but is only a pointer to a single int:
int* p = new int[5];

Bjarne Stroustrup would never suggest such nonsense, and you are incorrect
to say he does.
LOL does he?

Yes he does:
<quote ref: 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.
So tell us all then, which part of:

"For a type T, T* is the type "pointer to T". That is, a variable of type
T*
holds the address of type T."

in your mind says: "or an array of objects of type T" ?

Bjarne's statements are a __pointer definition__, as is what all of my
responses
to you have been in the context of. By failing to understand a most
simple, yet
technically precise pointer definition when you are presented with one,
then you
are certainly not competent enough to say what a pointer points to. That
is
irrefutable.
Apparently you are the one who fails to understand.
Your interpretation of what I suggest or what anyone suggests is the very
essence of you comprehension. You fail to realize that I am ONLY
asserting the
cases that were given to us by the author of the C++ language. I am not
the one
making up new cases that are loose in meaning and imprecise at best.
I understand you are typing complete bullshit. And I interpet what you say
as it is .. complete bullshit.
Nobody here but you is misinterpreting him. A 5th grader could process
his
pointer definition. The fact that you are making it some form of array
definition is the quintessential reason why you are not qualified to hold
a C++
discussion.
Nobody here but *YOU* is misinterpreting him.
As the list of people who openly disagree with you grows, so does the time
you
waste responding without thinking, to each and every one of them.
Fortunately
all you have to do is keep calling us all idiots to save face, right?

*plonk*
 
P

Paul

Leigh Johnston said:
On 23/03/2011 16:27, Paul wrote:
[...]
int (*p3)[dim] = &arr; /*Pointless extra level of indirection [see
note]*/
int** p4 = &arr; /*Same as above, but without typeinfo*/

Untrue; int (*p3)[dim] is not the same as int** (they are totally
unrelated types).
No they are related types. Related because:
int (*p3)[dim]; /*-- points to an array of int.---*/
int** p4; /* ---- points to an int* ---- */

The followings shows they both point to the same place:
int arr[5]={1,2,3,4,5};
int (*p)[5] = &arr;
int** pp = (int**)&arr;
std::cout<< "value of p:\t"<<p <<"\nvalue of pp:\t" <<pp;

I just forgot the cast.
 
S

SG

On 23/03/2011 16:27, Paul wrote:
[...]
int (*p3)[dim] = &arr; /*Pointless extra level of indirection [see note]*/
int** p4 = &arr; /*Same as above, but without typeinfo*/

Untrue; int (*p3)[dim] is not the same as int** (they are totally
unrelated types).

Good catch! This example speaks volumes. His wrongness apparently goes
beyond terminology issues. If his mental model makes him predict that
the above code will compile then his mental model is obviously wrong.

I'm not surprized, though. He's not the first one to trip over the
rather sneaky
- array-to-pointer standard conversion (§4.2)
- function parameter type transformations (§8.3)
- template argument deduction (§14.8.2)
rules. It's one of dangers of learning C++ via trial-and-error.

SG
 
P

Paul

They cannot accept that because their mental model about arrays,
objects, and pointers does not let them.

You were included when I said "they", therefore you should use the word "we"
when referrring to a group that includes yourself.
Their idea of a pointer is
something that points to exactly one thing and one thing only unless
it's a null pointer or a one-past-the-end pointer. And to what kind of
objects their pointers point to is statically controlled by the type
of the pointer. It's a different way of thinking about these things
that is more focused on types and that does not match your way of
thinking. I get that. You don't.
I understand they/you are wrong, you don't.
...which has been pointed out to be a flawed analogy given their
mental model about arrays, pointers and objects. It's an analogy that
only fits using your way of thinking.
Their/your mental model is wrong not my analogy.


<snip>
 
S

SG

The followings shows they both point to the same place:
int arr[5]={1,2,3,4,5};
int (*p)[5] = &arr;
int** pp = (int**)&arr;

std::cout<< "value of p:\t"<<p <<"\nvalue of pp:\t" <<pp;

I just forgot the cast.

How do you access an element of arr using pp? Is (*pp)[3] going to be
an lvalue referring to the fourth element of arr?

SG
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top