C++ Basic concepts. Pointers.

P

Paul

This discussion about pointers to arrays needs to be cleared up , there are
too many people around here posting incorrect technical terms and
misrepresenting them as technically correct..


Firstly let me point out what the C++ std states about pointers, from 3.9
Basic concepts:
"3 A pointer to objects of type T is referred to as a "pointer to T.""

Its follows from that if the objects pointed to are of type float a pointer
to them is a pointer to float, float*.
So lets see what a pointer to an array of floats looks like:
float arr_flts[64]={0};
float* p = arr_flts;

p is a pointer to an array of float objects. And correctly so as defined in
the standards, this can be further proven by dereferencing p in the
following:
float var_x = p[0];
The var_x will now correctly hold the value stored in the array at index 0.
This proves that when we dereference p we access the array of floats. This
is probably obvious to most people but perhaps not to all.

So it all seems quite straight forward, and everything works as it should. A
pointer to a sequence of T's, or an array of T's is actaully of type T*. But
some people disagree.


Some people have been arguing that p is not a pointer to the array but it
is only a pointer to a single element within the array. I have described
this as nonsense because given the bunch of bananas example , you cannot
point to a banana without also pointing at the bunch.
However they insist that a pointer to an array is of the following type:
float (*pp)[64] = &arr_flts;

This does not work because if this was a pointer to an array of floats, it
would return a float when derefenced but it doesn't . This pointer-type
points to an address, it is just a fancy pointer to pointer.
So this is not a pointer to an array of floats, it is a pointer to a
pointer, for example:
cout<< *pp;
The above will output an address, which seems to prove that pp points to
another pointer.
This pointer type is a pointer to objects of array-type, that is a pointer
to arrays of arrays or a single array.

But when we say this pointer points to a single array, the term array is
used in a different context. We are now talking about an array-type, not a
sequence of float objects. The array-type object we are now talking about
is bascially another pointer-type object, its not the entity that is the
array of floats.



So is it correct to say that a char* can only point to a single char and not
to an array of chars?
No their argument is fundamentally flawed because they are misinterpreting
the context of "an array of chars" from that meaning "a sequence of char
type objects" to mean an array-type object.
 
P

Paul

Leigh Johnston said:
This discussion about pointers to arrays needs to be cleared up , there
are too many people around here posting incorrect technical terms and
misrepresenting them as technically correct..

It has mostly been you doing that.
Firstly let me point out what the C++ std states about pointers, from
3.9 Basic concepts:
"3 A pointer to objects of type T is referred to as a "pointer to T.""

Its follows from that if the objects pointed to are of type float a
pointer to them is a pointer to float, float*.
So lets see what a pointer to an array of floats looks like:
float arr_flts[64]={0};
float* p = arr_flts;

p is a pointer to an array of float objects. And correctly so as defined

Wrong; p is a pointer to the first element of the array.
The standard clearly states that a pointer to objects(plural) of type T is
referred to as a "pointer to T".
So you are wrong, to suggest that this pointer points to one element only.
It has clearly been initialised to point to an array of floats, not just one
single float.

This pointer can be indexed to access any element in the array like so:
p[60]; /*Accesses the 60th element*/
Therefore this pointer points to an array of floats and not only to the
first element.
in the standards, this can be further proven by dereferencing p in the
following:
float var_x = p[0];

Pointer arithmetic on a pointer and dereferencing a pointer does not prove
that the pointer is a pointer to an array.

It proves that when dereferenced it accesses the array of float objects.
Therefore it further proves that it is a pointer to the array of float
objects.


All it proves is that array-to-pointer conversion, pointer arithmetic and
pointer dereferencing work.


T* is a pointer-to-T nothing more; if T is not an array then T* is not a
pointer to an array.

No you are wrong , T* can point to an array of T's.
That is correct.


No it is not nonsense; what is nonsense is your bananas analogy...
It is nonsense. The banana thing works.
you cannot point to a banana without also pointing at the bunch.
However they insist that a pointer to an array is of the following type:
float (*pp)[64] = &arr_flts;

That is a pointer to an array yes.
This does not work because if this was a pointer to an array of floats,
it would return a float when derefenced but it doesn't . This

No; as it is a pointer to an array of floats deferencing it should result
in a reference to an array of floats not a float (which is what will
happen).

A pointer to a T points to a T, not to some other object that references a
T.
You have once again shown you are trully worthy of donning the dunce cap.
Wrong; tt is not a pointer to pointer at all.


No it doesn't prove pp points to another pointer; it proves that
array-to-pointer conversion is working.


Huh? Gibberish.
You don't understand something?
Huh? Gibberish.
Again there is obviously something you dont understand.
Yes it is correct to say that.


Huh? Gibberish.
No technically accurate and correct facts.
 
J

Juha Nieminen

Paul said:
This discussion about pointers to arrays needs to be cleared up

Will you ever stop, mister "I don't have anything else to say about
this subject"?

What? Are you going to continue this for years and years?
 
P

Paul

Juha Nieminen said:
Will you ever stop, mister "I don't have anything else to say about
this subject"?

What? Are you going to continue this for years and years?
Was just clearing things up following a small group of people agreed on an
incorrect misinterpretation and it was presented in such a way that people
might actually think they were correct.

Sometimes these people, though genuinely idiots when it comes to the
technicalities of C++, have other skills in misrepresenting an idea and can
present it in such a way that they appear to be correct.

Even though they are saying that Bjarne Stroustrup is sloppy in his use of
language and innaccurate, they actaully manage to pull this off by their
msinterpretations and manipualtaion of english which shows their skills in
misrepresentation.

I will probably give up soon because I can't be bother fighting ten idiots
at a time, some of them are just opposing me becasue I have proved them
wrong in a past argument.
The likes of that Ian Collins who tried to tell me there was only one
standard? I corrected him an he learned something new, but does he thank me
for it? no He hates me for it because I made him look silly
:) Such is life there is just no pleasing some people.
 
D

Default User

Juha Nieminen said:
Will you ever stop, mister "I don't have anything else to say about
this subject"?

What? Are you going to continue this for years and years?

Probably, as long as people keep swallowing the troll bait.



Brian
 

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

Latest Threads

Top