Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C++ Basic concepts. Pointers.

Reply
Thread Tools

C++ Basic concepts. Pointers.

 
 
Paul
Guest
Posts: n/a
 
      04-21-2011
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.


 
Reply With Quote
 
 
 
 
Puppet_Sock
Guest
Posts: n/a
 
      04-21-2011
On Apr 21, 11:53*am, "Paul" <(E-Mail Removed)> wrote:
[whatever]

yInenchoH
 
Reply With Quote
 
 
 
 
Paul
Guest
Posts: n/a
 
      04-21-2011

"Leigh Johnston" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On 21/04/2011 16:53, Paul wrote:
>> 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.



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

>
> All it proves is that array-to-pointer conversion, pointer arithmetic and
> pointer dereferencing work.
>
>>
>> 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.

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

>
> That is correct.
>
>> described this as nonsense because given the bunch of bananas example ,

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

>
>> pointer-type points to an address, it is just a fancy pointer to pointer.

>
> Wrong; tt is not a pointer to pointer at all.
>
>> 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.

>
> No it doesn't prove pp points to another pointer; it proves that
> array-to-pointer conversion is working.
>
>> This pointer type is a pointer to objects of array-type, that is a
>> pointer to arrays of arrays or a single array.

>
> Huh? Gibberish.

You don't understand something?
>
>>
>> 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.

>
> Huh? Gibberish.

Again there is obviously something you dont understand.
>
>>
>>
>>
>> So is it correct to say that a char* can only point to a single char and
>> not to an array of chars?

>
> Yes it is correct to say that.
>
>> 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.

>
> Huh? Gibberish.

No technically accurate and correct facts.

 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      04-21-2011

"Puppet_Sock" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On Apr 21, 11:53 am, "Paul" <(E-Mail Removed)> wrote:
[whatever]

Yup Whatever

 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      04-22-2011
Paul <(E-Mail Removed)> wrote:
> 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?
 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      04-22-2011

"Juha Nieminen" <(E-Mail Removed)> wrote in message
news:4db13660$0$2878$(E-Mail Removed)...
> Paul <(E-Mail Removed)> wrote:
>> 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?
>

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.

 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      04-22-2011

"Juha Nieminen" <(E-Mail Removed)> wrote in message
news:4db13660$0$2878$(E-Mail Removed)...
> Paul <(E-Mail Removed)> wrote:
>> 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?


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



Brian


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TurboTax Basic vs. Taxcut Basic? Sharp Dressed Man Computer Support 1 01-12-2009 12:52 PM
What is the difference between Visual Basic.NET and Visual Basic 6? Jimmy Dean Computer Support 3 07-25-2005 07:05 AM
Re: Python interpreter in Basic or a Python-2-Basic translator. rrr@ronadam.com Python 0 05-02-2005 01:48 PM
Python interpreter in Basic or a Python-2-Basic translator. Engineer Python 6 05-01-2005 10:16 PM
Upgrading Microsoft Visual Basic 6.0 to Microsoft Visual Basic .NET Jaime MCSD 2 09-20-2003 05:16 AM



Advertisments