Is this wrong for C++?


P

Paul

<quote ref: http://c-faq.com/aryptr/aryptr2.html >
The array declaration char a[6] requests that space for six characters be
set aside, to be known by the name ``a''. That is, there is a location named
``a'' at which six characters can sit. 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
</quote>

I have found many other texts by the likes of Bjarne Stroustrup and many
other highly respected C+ authorities that is in agreement with the above.
So how can it be that the majority of this newsgroup disagree with all these
experts?
Are these experts somehow incorrect?
 
Ad

Advertisements

P

Paul

Paul said:
This pointer can point almost anywhere: to any char, or to any contiguous
array of chars, or nowhere
</quote>
I'll leave the relevant piece of the quote.

<snip>
So it seems the 3 people who have responded to this post are 3 of the people
who repeatedly claimed that with:
int* p = new int[16];
p was not a pointer to an array and that it was a pointer to a single
element only.


I put it to this newsgroup that these 3 people have no clue what they are
talking about and are in direct conflict with the opinions of respected C++
authorities.
Not only that but they are also in direct conflict with statements in the
C++ standards , ref dereferencing and array produces a pointed to(n-1)
dimensional array.

They can bark all they like about how it is only me that is wrong and how
they know it all, but its a simple fact that they are nothing more than
idiots who are experts on nothing more than bullshitting and twisting
fabricated misinterpretations.
 
J

Joshua Maurice

So it seems the 3 people who have responded to this post are 3 of the people
who repeatedly claimed [...]

Make that at least 6. Myself, James Kanze, Noah Roberts. I'm sure I
could whip up a few more names if I cared to look through those
threads.

I'm lending moral support, though I ask again why you're still talking
to the troll even after he's made like a dozen different obvious troll
threads in a few days. It's getting close to the automated sex bot
spam. (Which at least google has seemed to thankfully block in here.
Yes, I need to get a real newsreader.)
 
P

Paul

So it seems the 3 people who have responded to this post are 3 of the
people
who repeatedly claimed [...]

Make that at least 6. Myself, James Kanze, Noah Roberts. I'm sure I
could whip up a few more names if I cared to look through those
threads.

I'm lending moral support, though I ask again why you're still talking
to the troll even after he's made like a dozen different obvious troll
threads in a few days. It's getting close to the automated sex bot
spam. (Which at least google has seemed to thankfully block in here.
Yes, I need to get a real newsreader.)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Looks like another self-proclaimed idiot who can't accept the truth.
 
G

Goran

So it seems the 3 people who have responded to this post are 3 of the people
who repeatedly claimed that with:
int* p = new int[16];
p was not a pointer to an array and that it was a pointer to a single
element only.

This has been beaten to death, and I have no intention to browse
through filth, so... Has this discussion been here:

int* p;
p = new int[16]; // 1
int a[2];
p = a; // 2
int i;
p = &i; // 3

?

Paul, if "p" is a pointer to an array, what about (3)? "i" is not an
array, so how come "p" can point to it? Are you suggesting that type
system is broken, so that e.g. address-of magically produces pointers
to arrays, or...?

The explanation is rather simple:

In (1), operator new allocates contiguous space for 16 objects and
returns pointer to the first one (but see (2)).

In (2), a is array of two ints. And yet, p=a works. How come? If p is
a pointer to an array, and if (1) works, surely p is a pointer to an
array of 16 ints, in which case it's not a pointer to an array of 2
ints. And also, if it's a pointer to an array of 2 ints, why aren't we
using address-of operator, p = &a?

The answer to that is simple: in (1), operator new allocates
contiguous space for 16 objects and returns pointer to the first one.
In (2), array type erasure (or decay) takes place. You can think of
"=" as a following function call: int* operator=(int[]). (Array type
erasure is mentioned in in 6.4 http://c-faq.com/aryptr/aryptrparam.html,
and it's where your argument breaks apart).

So... A pointer to type always points to one instance of a type (not
an array thereof). But pointers and arrays are similar, so e.g. p[1]
and a[1] from (2) would produce same result (e.g. 6.3 talks about that
http://c-faq.com/aryptr/aryptrequiv.html). Can you live with that?

Goran.
 
Ad

Advertisements

S

SG

This has been beaten to death, and I have no intention to browse
through filth, so... Has this discussion been here:

int* p;
p = new int[16]; // 1
int a[2];
p = a; // 2
int i;
p = &i; // 3

?

Paul, if "p" is a pointer to an array, what about (3)? "i" is not an
array, so how come "p" can point to it? Are you suggesting that type
system is broken, so that e.g. address-of magically produces pointers
to arrays, or...?

You simply have to keep in mind that his wording
"is a pointer to an array"
translates to
"currently points to an element of an array".

He does not speak about the type of the pointer (which does not
change) but about what address it holds (at runtime). And when it
holds the address of an array element, he says "it is a pointer to an
array". That's just his way of expressing these things. The thing you
had in mind while reading "is a pointer to an array" is actually "is a
pointer to an array-type object" in the Paul-speak language.

I still think that his language has been influenced by a couple of
misunderstandings w.r.t. arrays. That would also explain at least one
thread title of his ("an array is just a pointer"). But his
personality doesn't allow him to admit something like this.

SG
 
P

Paul

So it seems the 3 people who have responded to this post are 3 of the
people
who repeatedly claimed that with:
int* p = new int[16];
p was not a pointer to an array and that it was a pointer to a single
element only.

So... A pointer to type always points to one instance of a type (not
an array thereof).
<snip>

I disagree with you and so do all the experts.
 
Ad

Advertisements

G

Goran

--No. I think I offered a reasonable analysis and a correct explanation.
--Please, where am I wrong?

Top of page

I can't see how top of page shows me wrong. But OK, I'll try:
seemingly relevant part of the first post is the following:

"pointer can point almost anywhere: to any char, or to any contiguous
array of chars"

Even the very words I quoted do not say that said pointer __is__ a
pointer to an array. They merely say that pointer __points__ to said
array, and that is, sadly, somewhat imprecise. Lack of precision is
not normally relevant, but OK, you insist. So... The explanation I
offered shows various facets of the issue better.

(At the danger of repeating myself...) What __might happen__ is that
pointer points to a place in memory where there's several instances of
type, one after another. When that is the case, indexing the pointer
produces same result as if pointer was an array and we were indexing
the array. But this is where the buck stops. What you seem to be doing
is the following logic leap: when pointer points to the first element
of an array, it __is__ a pointer to an array. That is strictly not
true. Elsewhere people did show what "pointer to an array" is, that's
not in any way unclear.

Goran.
 
P

Paul

I can't see how top of page shows me wrong. But OK, I'll try:
seemingly relevant part of the first post is the following:
Look at top of page and you will find the answer to "What part of my
argument is wrong?"
"pointer can point almost anywhere: to any char, or to any contiguous
array of chars"
This a toal condraction to what you said at top of the page.
Even the very words I quoted do not say that said pointer __is__ a
pointer to an array. They merely say that pointer __points__ to said
array, and that is, sadly, somewhat imprecise. Lack of precision is
not normally relevant, but OK, you insist. So... The explanation I
offered shows various facets of the issue better.

(At the danger of repeating myself...) What __might happen__ is that
pointer points to a place in memory where there's several instances of
type, one after another. When that is the case, indexing the pointer
produces same result as if pointer was an array and we were indexing
the array. But this is where the buck stops. What you seem to be doing
is the following logic leap: when pointer points to the first element
of an array, it __is__ a pointer to an array. That is strictly not
true. Elsewhere people did show what "pointer to an array" is, that's
not in any way unclear.

Sorry I don't know what you are talking about, and neither do you by the
looks of things.
 
D

Drew Lawson

I can't see how top of page shows me wrong. But OK, I'll try:

Might I suggest that you don't.

My experience as a viewer of The Paul Show is that he throws out
intentionally vague or crypticly phrased objections with full
knowledge that they cannot be unambiguously answered. Any attempt
will be stamped as wrong, again without any detail as to what his
objection is.

It is a game that is briefly amusing when played with a 4 year-old.

Of course, on the occasions that Paul makes the mistake of stating
a specific objection, someone responds with a specific and detailed
rebuttal. This results in Paul calling the poster an idiot.

He isn't here to learn. He's here to see how long people will jump
like cats when he wiggles a feather toy.
 
P

Paul

Drew Lawson said:
Might I suggest that you don't.

My experience as a viewer of The Paul Show is that he throws out
intentionally vague or crypticly phrased objections with full
knowledge that they cannot be unambiguously answered. Any attempt
will be stamped as wrong, again without any detail as to what his
objection is.

It is a game that is briefly amusing when played with a 4 year-old.

Of course, on the occasions that Paul makes the mistake of stating
a specific objection, someone responds with a specific and detailed
rebuttal. This results in Paul calling the poster an idiot.

He isn't here to learn. He's here to see how long people will jump
like cats when he wiggles a feather toy.

Interesting theory.
You should be an online phycologist, analysing people without even seeing
them is obviously one of your traits :)
 
Ad

Advertisements

D

Drew Lawson

I see
no problem with people correcting the C++ related things that he says.

I agree. We disagree on whether it will have any benefit.

But the only harm is encouraging a troll, and this one seems to
require little encouragement.
 
M

Michael Tsang

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
<quote ref: http://c-faq.com/aryptr/aryptr2.html >
The array declaration char a[6] requests that space for six characters be
set aside, to be known by the name ``a''. That is, there is a location
named ``a'' at which six characters can sit. 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
</quote>

I have found many other texts by the likes of Bjarne Stroustrup and many
other highly respected C+ authorities that is in agreement with the above.
So how can it be that the majority of this newsgroup disagree with all
these experts?
Are these experts somehow incorrect?

p is a pointer to char, *not* a pointer to *array* of char

char (*q)[6] = &a; *is* a pointer to *array* of char
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAk2XNKsACgkQZ1Turg5KUCm3cQCeLa3nRje2WfS4VplZw+5vW+xf
OHIAn1vUNmnZGu+PtpnBhbz7yv6aCBVD
=JiKr
-----END PGP SIGNATURE-----
 
P

Paul

Michael Tsang said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
<quote ref: http://c-faq.com/aryptr/aryptr2.html >
The array declaration char a[6] requests that space for six characters be
set aside, to be known by the name ``a''. That is, there is a location
named ``a'' at which six characters can sit. 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
</quote>

I have found many other texts by the likes of Bjarne Stroustrup and many
other highly respected C+ authorities that is in agreement with the
above.
So how can it be that the majority of this newsgroup disagree with all
these experts?
Are these experts somehow incorrect?

p is a pointer to char, *not* a pointer to *array* of char

As the experts have said p can point almost anywhere. You are obviously
another thicko if you cannot understand the basics of pointers.
 
Ad

Advertisements

H

hanukas

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Paul wrote:
<quote ref:http://c-faq.com/aryptr/aryptr2.html>
The array declaration char a[6] requests that space for six charactersbe
set aside, to be known by the name ``a''. That is, there is a location
named ``a'' at which six characters can sit. 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
</quote>
I have found many other texts by the likes of Bjarne Stroustrup and many
other highly respected C+ authorities that is in agreement with the
above.
So how can it be that the majority of this newsgroup disagree with all
these experts?
Are these experts somehow incorrect?
p is a pointer to char, *not* a pointer to *array* of char

As the experts have said p can point almost anywhere. You are obviously
another thicko if you cannot understand the basics of pointers.

char *name = "Paul";
char *p = name;

Now p is a pointer to idiot.
 

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

Top