On generally accepted terminology for pointers and arrays

  • Thread starter Alf P. Steinbach /Usenet
  • Start date
A

Alf P. Steinbach /Usenet

* cpp4ever, on 12.04.2011 18:39:
You failed to understand it the first time, effectively accusing me of
being a troll.

I think, if you could just clarify what your "it" is?

I would love to help.

If you could only communicate a little, like, at least hinting what you're
talking about.

I no longer have any interest in either trying to
understand your point, or make myself understood.

Well, you have not yet attempted to specify the "it" that you are confused about.

Unfortunately I'm not telepathic.

You have to make *some* effort at communication.

Apparently you are the
peer reviewed expert and obviously have no need to understand such
trivialities any further.

Thanks!

Also for earlier compliments.


Cheers & hth.,

- Alf
 
P

Paul

Noah Roberts said:
Since my killfile works I only see one side of the numerous debates here
about pointers and arrays.

But it does seem to be pretty confrontational.

So, herewith, me on the subject of how to talk about pointers & arrays.

When I wrote my (peer reviewed) pointers tutorial I discovered that even
the acknowledged international experts did not agree on the meaning of
"pointer". Happily the disagreements were mainly of the single kind
exemplified by

Hey, you can't call THAT a pointer (because I don't)!

Some objected to calling variables pointers, others objected to calling
pointer values pointers, and yet others objected to calling pointer
types pointers, even though the Holy Standard does. In case the latter
is difficult to grok: I'm talking about utterances like "it's a pointer"
and "it's a car", instead of spelling it out more literally like "it's a
something of pointer type" and "it's an object that conforms to the
requirements of the 'car' type of vehicle". I never understood the point
of making such subtle distinctions, but apparently some who are smarter
and/or more knowledgable than me, do. And what about smart pointers? If
they are accepted as pointers, then a pointer needs not necessarily be a
pointer of the kind that the language supports directly. So what we have
is a word that becomes more vague the larger the context is.

Happily, that means that as one narrows the context, one also narrows
down the possible meanings of "pointer". Narrowing it down to the
pointers directly supported by the C++ language, the RAW POINTERS of
C++, there is almost no ambiguity. In this very limited context the term
is well-defined.

The term "pointer" is an abstraction. It means different things in
different languages. This is why it's important to use standard
terminology, especially when trying to correct misconceptions. There's
not much point arguing with people who insist that you can't call what the
standard calls pointers, pointers. There is no sense in which they can be
said to be correct, and that is the important part of conversation.

The important parts about pointers are that you can gain them in certain
ways (like using &) and you can dereference them. Those two conceptual
operations make a pointer what it is. The type that you get when you
dereference the pointer is what it points to.

This is why it makes sense to call a smart pointer a pointer; it
implements the operations of a pointer. Anything that implements the
operations of a pointer IS a pointer.
The second way in which a pointer can point to an array, is the answer
to question 3, namely

int a[42];
int* p2 = a; // OK, p2 is a pointer to an array (dynamically).

No. The p2 variable is a pointer to int because an int is what you get
when you dereference it.
3) And a pointer of type T* be said to point to an array of T, but only
in the dynamic sense, like "right now it points to an array".


The other important part of pointers is that when the point to elements of
an array, you can perform math on them. This fact though does not change
what type you get when you dereference the pointer. To claim that a
pointer points at anything other than what you get when you dereference it
flies in the face of the concept of "pointer". You can't correctly claim,
in any way that makes sense, that p2 points to an array because that's NOT
what you get when you dereference the pointer.

You could reasonably claim that p2 points INTO an array, but this is quite
a different statement.

When dereferenced, a pointer to an array does not yeild what it points to
but a (n-1) dimensional array.
You are obviously unaware of the part of the standard that explains pointers
to arrays:

"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".
 
A

Alf P. Steinbach /Usenet

* Noah Roberts, on 12.04.2011 18:37:
On 4/11/2011 7:00 PM, Alf P. Steinbach /Usenet wrote: [snip]
The second way in which a pointer can point to an array, is the answer
to question 3, namely

int a[42];
int* p2 = a; // OK, p2 is a pointer to an array (dynamically).

No.

That's silly (see below).

The p2 variable is a pointer to int because an int is what you get when you
dereference it.
Yes.




The other important part of pointers is that when the point to elements of an
array, you can perform math on them. This fact though does not change what type
you get when you dereference the pointer. To claim that a pointer points at
anything other than what you get when you dereference it flies in the face of
the concept of "pointer".

Here is one counter-example to your claim:

int x;
void* p = &x;

p cannot be derferenced. Hence in your view a claim that it points to/at x
"flies in the face of the concept of pointer".

Do you now see that that's an impractical, silly view?


Cheers & hth.,

- Alf
 
C

cpp4ever

* cpp4ever, on 12.04.2011 18:39:

I think, if you could just clarify what your "it" is?

I would love to help.

If you could only communicate a little, like, at least hinting what
you're talking about.



Well, you have not yet attempted to specify the "it" that you are
confused about.

Unfortunately I'm not telepathic.

You have to make *some* effort at communication.



Thanks!

Also for earlier compliments.


Cheers & hth.,

- Alf
 
P

Peter Remmers

Am 12.04.2011 20:06, schrieb Noah Roberts:

Troll-calling is almost as bad a name calling. Alf made a legitimate
statement, and it has been a neutral discussion until the troll calling.
That narrow-minded "don't want to hear" attitude is just the same as
Paul's - an unability to accept or at least consider others' points when
they do not match your own. Just because Alf's statement goes into the
direction of Paul's views, that alone does not justify calling him a troll.


Peter
 
P

Paul

Alf P. Steinbach /Usenet said:
* Noah Roberts, on 12.04.2011 18:37:
On 4/11/2011 7:00 PM, Alf P. Steinbach /Usenet wrote: [snip]
The second way in which a pointer can point to an array, is the answer
to question 3, namely

int a[42];
int* p2 = a; // OK, p2 is a pointer to an array (dynamically).

No.

That's silly (see below).

The p2 variable is a pointer to int because an int is what you get when
you
dereference it.

Yes.
Wrong there is an exception in rhe C++ standards for pointers to arrays. See
the section on Arrays.
When dereferenced, a pointer to an array does not yield what it points to
but a (n-1) dimensional array.
 
N

Noah Roberts

Am 12.04.2011 20:06, schrieb Noah Roberts:

Troll-calling is almost as bad a name calling. Alf made a legitimate
statement, and it has been a neutral discussion until the troll calling.

I don't see responding to argument by calling people's views silly to be
"neutral". I see it as nothing short a trolling tactic. Your opinion
obviously differs.

Normally Alf doesn't troll and I didn't call him one. He is now though.
 
P

Peter Remmers

Am 12.04.2011 20:05, schrieb cpp4ever:

[in a huff - acting like a 6 year-old]


OMG is this kindergarten?

Peter
 
A

Alf P. Steinbach /Usenet

* cg_chas, on 12.04.2011 20:15:
* Noah Roberts, on 12.04.2011 18:37:
On 4/11/2011 7:00 PM, Alf P. Steinbach /Usenet wrote: [snip]

The second way in which a pointer can point to an array, is the answer
to question 3, namely

int a[42];
int* p2 = a; // OK, p2 is a pointer to an array (dynamically).


No.

That's silly (see below).

The p2 variable is a pointer to int because an int is what you get when you
dereference it.
Yes.


3) And a pointer of type T* be said to point to an array of T, but only
in the dynamic sense, like "right now it points to an array".


The other important part of pointers is that when the point to elements of an
array, you can perform math on them. This fact though does not change what type
you get when you dereference the pointer. To claim that a pointer points at
anything other than what you get when you dereference it flies in the face of
the concept of "pointer".

Here is one counter-example to your claim:

int x;
void* p =&x;

p cannot be derferenced. Hence in your view a claim that it points to/at x
"flies in the face of the concept of pointer".
Ok now I am starting to think that you and Paul are drinking from the same well.
:)

Don't know about Paul, because he's in my killfile.

But in case it was not obvious, the above exemplifies a direct
self-contradiction in Noah's view.

I think that when a self-contradiction is pointed out, then about the least
reasonable response is to snip the short argument and add a personal attack.
Hence, I plonked him, also because of his earlier allegations about sexual
deviations of Johannes Schaub. And similarly, in the case of Paul, killfiled in
part because of earlier allegations about sexual deviations of Francis
Glasborrow, and in the case of Leigh I remember killfiling him for a tirade
about Pete Becker, on top of generally trollish behavior, but I may have been
wrong, judging from glimpses I've had. But at least regarding Paul and Noah,
these folks are really *real* trolls, people who just love to stir up a fight
and who write all kinds of nasty stuff about others, make no mistake about it.

Of course a void pointer is an exception. We could also cast the pointer to an
infinite number of types and expect infinitely different types of yielded
values.

He does not assert that all pointers must be dereferenceable, just that
dereferencing the int* in the former example yields an int.

No, what Noah wrote, which is quoted in context above, was


"To claim that a pointer points at anything other than what you get when you
dereference it flies in the face ofthe concept of "pointer".


If, then, he supported the claim that


p points to x


then he would be claiming that p points to something other than what you get
when you dereference it, and hence in his own view that support for the
statement "p points to x" would fly in the face of the concept of "pointer".

Hence Noah cannot reasonably be supporting the view that p points to x.

However, just about everybody else would agree that p points to x.

I am guessing that for example you, too, agree with that.

Be that as it may (about your agreement or not), Noah's view, where p cannot
point to anything, is not in line with the general consensus about the
terminology here. And so it is quite irrelevant as an argument about pointers
that point to arrays, or not. Invalid is invalid, however sweet it may sound.

[snipped irrelevant argumentantion]


Cheers & hth.,

- Alf
 
P

Peter Remmers

Am 12.04.2011 20:33, schrieb Noah Roberts:
I don't see responding to argument by calling people's views silly to be
"neutral". I see it as nothing short a trolling tactic. Your opinion
obviously differs.

Normally Alf doesn't troll and I didn't call him one. He is now though.

I wouldn't perceive that to be an insulting name calling quite yet.

Fact is that there are two sides. There's the object that lives at a
certain memory location and that has a type. And then there's the
pointer that holds the object's address, and that also has a type.

As long as the types agree, all is well. The problems start as soon as
they differ. There are levels in between. There are "compatible" types,
or the pointer points to a subobject of a matching type, etc.

I totally agree with Alf that it is impractical, and thus silly, to
close your eyes for one of the two sides. You close your eyes for one
side, Paul for the other.


Peter
 
P

Paul

Peter Remmers said:
Am 12.04.2011 20:33, schrieb Noah Roberts:

I wouldn't perceive that to be an insulting name calling quite yet.

Fact is that there are two sides. There's the object that lives at a
certain memory location and that has a type. And then there's the pointer
that holds the object's address, and that also has a type.

As long as the types agree, all is well. The problems start as soon as
they differ. There are levels in between. There are "compatible" types, or
the pointer points to a subobject of a matching type, etc.

I totally agree with Alf that it is impractical, and thus silly, to close
your eyes for one of the two sides. You close your eyes for one side, Paul
for the other.
Yes there are two sides:
a) People like me who accept what the standard defines about pointers to
arrays. That is, when dereferenced, a pointer to an array yeilds an (n-1)
dimensional array.

b) Idiots who don't accept this.

I believe the majority of people invovled in this discussion, including you,
are on side b. As for Alf, he obviously thinks he is some expert nowadays
and perhaps he is to some but hes no different to me now than he was when I
was correcting him 15 years ago.
 
P

Paul

Alf P. Steinbach /Usenet said:
* cg_chas, on 12.04.2011 20:15:
* Noah Roberts, on 12.04.2011 18:37:
On 4/11/2011 7:00 PM, Alf P. Steinbach /Usenet wrote:
[snip]

The second way in which a pointer can point to an array, is the answer
to question 3, namely

int a[42];
int* p2 = a; // OK, p2 is a pointer to an array (dynamically).


No.

That's silly (see below).


The p2 variable is a pointer to int because an int is what you get when
you
dereference it.

Yes.


3) And a pointer of type T* be said to point to an array of T, but
only
in the dynamic sense, like "right now it points to an array".


The other important part of pointers is that when the point to elements
of an
array, you can perform math on them. This fact though does not change
what type
you get when you dereference the pointer. To claim that a pointer
points at
anything other than what you get when you dereference it flies in the
face of
the concept of "pointer".

Here is one counter-example to your claim:

int x;
void* p =&x;

p cannot be derferenced. Hence in your view a claim that it points to/at
x
"flies in the face of the concept of pointer".
Ok now I am starting to think that you and Paul are drinking from the
same well.
:)

Don't know about Paul, because he's in my killfile.

But in case it was not obvious, the above exemplifies a direct
self-contradiction in Noah's view.

I think that when a self-contradiction is pointed out, then about the
least reasonable response is to snip the short argument and add a personal
attack. Hence, I plonked him, also because of his earlier allegations
about sexual deviations of Johannes Schaub. And similarly, in the case of
Paul, killfiled in part because of earlier allegations about sexual
deviations of Francis Glasborrow, and in the case of Leigh I remember
killfiling him for a tirade about Pete Becker, on top of generally
trollish behavior, but I may have been wrong, judging from glimpses I've
had. But at least regarding Paul and Noah, these folks are really *real*
trolls, people who just love to stir up a fight and who write all kinds of
nasty stuff about others, make no mistake about it.
I didn't make any allegations about Francis sexual deviatons, as you say, I
said he had a Big Gay Following and I believe you were one of those
followers. :)

TY for categorizing me as a *real* troll. :)
 
C

cpp4ever

Am 12.04.2011 20:05, schrieb cpp4ever:

[in a huff - acting like a 6 year-old]


OMG is this kindergarten?

Peter

Might as well be, this is just one big trolling exercise IMHO
 
N

Noah Roberts

I totally agree with Alf that it is impractical, and thus silly, to
close your eyes for one of the two sides. You close your eyes for one
side, Paul for the other.

You are bordering on troll behavior here too. My eyes are not closed.
I gave a response to Alf's side, he responded poorly, and I decided the
conversation was pointless. I gave him a chance even though he wasn't
actually making any new points regarding the conversation.

I consider the issue dead. Those who want to continue misusing the term
"pointer to array" are not convincible by ANY measure. Alf for instance
is simply responding to all argument to the contrary by calling it
"lawyeresque". It's not worth my time.

Now, if you want to call that closing my eyes then I really don't give a
damn. I'm not going to be responding any further. You can either take
it as a difference of opinion or you can continue riding your high horse
and lecturing me about your perceived ills. If you expect me to justify
myself to you then that's YOUR problem.
 
I

Ian Collins

[
other safe things :-
downcasting to a pointer-to-type-from-which-our-pointed-to-type is
derived.
upcasting to a pointer-to-more-derived-type, as long as I check for
dynamic_cast<> returning NULL
]


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
According to Leigh Johnston your idea of upcasting and downcasting is
back-to-front and wrong.

I also see casting up as casting to a more derived object, but I can see
how it can be seen the other way. I don't really remember what is the
more generally used terminology and I cant be bothered researching it
for the sake of arguing with people who will never accept any logical
conclusion.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Yes we already know that you dislike technical correctness but at least
you have admitted it now by confirming that you cannot be bothered
researching issues properly.

Issues such as configuring news clients...
 
A

Alf P. Steinbach /Usenet

* gwowen, on 12.04.2011 09:16:
[replying to self - bad me]
Speaking personally, I find it helpful to think of pointers as
modelling two distinct concepts.

i) A nullable, reseatable reference to a single (possibly polymorphic)
object.
I can use it to access the members of the base type to which it has
been declared to point. Trying anything else is fraught with danger
(even obtaiining a copy of the object (due to slicing)).

[
other safe things :-
downcasting to a pointer-to-type-from-which-our-pointed-to-type is
derived.
upcasting to a pointer-to-more-derived-type, as long as I check for
dynamic_cast<> returning NULL
]

ii) A bi-directional iterator into a contiguous collection of non-
polymorphic objects.

[
I meant "random access iterator" not bidirectional, with the array
access ptr[n] being syntactic sugar for *(ptr+n)
]

The "points into" is quite useful, I think not technically (because technically
any pointing into middle of array is also a pointing to start of sub-array,
ouch!) but it allows people some terminological & psychological elbow-room. ;-)

* * *

Re "downcast" and "upcast", you got those directions backward wrt. common
terminology, but I think you were aware of that possibility since you took such
pains to describe what you meant in detail.

With conventional terminology, for single inheritance "up" is in the direction
up the class inheritance chain, towards the top base class, and "down" is in the
direction down the chain, towards the most specific derived class.

In the more general case we have a class derivation tree with many roots, but
the same applies: the roots are in the direction of up.

However, it has not always been a universal convention to think of and draw such
abstract trees with root(s) upward. Donald Knuth changed his presentation from
first edition to second edition of "The Art of Computer Programming". So,
somewhere there at the start of the 1970's, apparently, the notion of trees with
roots in the air, became the common way to think of it and talk about it.

* * *

Re the two kinds of pointers, yes it's technically a shortcoming of the C++ type
system. But then so is the failure to distinguish pointers to automatically
allocated objects from pointers to dynamically allocated objects. And so on. The
various combinations of properties to distinguish explodes exponentially. I'm
not aware of any good answer, although a RAND corporation employee (as I recall)
once posted to clc++m a proposal to replace use of raw pointers with use of
smart pointers that modeled these concepts/distinctions.


Cheers & hth.,

- Alf
 
P

Peter Remmers

Am 12.04.2011 21:47, schrieb Noah Roberts:
You are bordering on troll behavior here too. My eyes are not closed.

You are pretty quick with the word troll. If stating an opinion that you
don't like constitutes trolling then you're no better than Paul, because
accusing someone of trolling for no better reason is no less of an
insult than direct name calling. You may as well be honest and use the
word "idiot" or something and don't masquerade your insults behind the
word "troll"...
int a[42];
int* p2 = a; // OK, p2 is a pointer to an array (dynamically).
No. The p2 variable is a pointer to int because an int is what you get
when you dereference it.

You're not closing your eyes? That statement is correct but it is only
one side of the story.
I gave a response to Alf's side, he responded poorly, and I decided the
conversation was pointless. I gave him a chance even though he wasn't
actually making any new points regarding the conversation.

What chance? You were not content with his answer and unholstered your
troll-calling gun. Nice shootin' cowboy.

I consider the issue dead. Those who want to continue misusing the term
"pointer to array" are not convincible by ANY measure. Alf for instance
is simply responding to all argument to the contrary by calling it
"lawyeresque". It's not worth my time.

Now, if you want to call that closing my eyes then I really don't give a
damn. I'm not going to be responding any further. You can either take
Yeah. "Don't give a damn". Join Paul's and cpp4ever's club.
it as a difference of opinion or you can continue riding your high horse
and lecturing me about your perceived ills. If you expect me to justify
myself to you then that's YOUR problem.

I'm just saying that fanatically defending a viewpoint, no matter which,
with questionable methods, be it direct insults or troll accusations,
and completely denying the validity of other possible POVs is a bad thing.


Peter
 

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,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top