C++ Basic concepts. Pointers.

Discussion in 'C++' started by Paul, Apr 21, 2011.

  1. Paul

    Paul Guest

    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.
     
    Paul, Apr 21, 2011
    #1
    1. Advertising

  2. Paul

    Puppet_Sock Guest

    On Apr 21, 11:53 am, "Paul" <> wrote:
    [whatever]

    yInenchoH
     
    Puppet_Sock, Apr 21, 2011
    #2
    1. Advertising

  3. Paul

    Paul Guest

    "Leigh Johnston" <> wrote in message
    news:...
    > 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.
     
    Paul, Apr 21, 2011
    #3
  4. Paul

    Paul Guest

    "Puppet_Sock" <> wrote in message
    news:...
    On Apr 21, 11:53 am, "Paul" <> wrote:
    [whatever]

    Yup Whatever :)
     
    Paul, Apr 21, 2011
    #4
  5. Paul <> 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?
     
    Juha Nieminen, Apr 22, 2011
    #5
  6. Paul

    Paul Guest

    "Juha Nieminen" <> wrote in message
    news:4db13660$0$2878$...
    > Paul <> 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.
     
    Paul, Apr 22, 2011
    #6
  7. Paul

    Default User Guest

    "Juha Nieminen" <> wrote in message
    news:4db13660$0$2878$...
    > Paul <> 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
     
    Default User, Apr 22, 2011
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Riken

    OOPS concepts

    Riken, Jul 15, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    17,296
    bmundy
    Aug 6, 2003
  2. Amir Pashazadeh

    .net and descriptive concepts!

    Amir Pashazadeh, Jul 17, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,049
    Amir Pashazadeh
    Jul 18, 2003
  3. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    694
  4. Trans
    Replies:
    0
    Views:
    158
    Trans
    Apr 23, 2006
  5. TwistedRoar

    Practice of basic concepts

    TwistedRoar, Jan 1, 2014, in forum: C++
    Replies:
    12
    Views:
    191
    Luca Risolia
    Jan 5, 2014
Loading...

Share This Page