Is this wrong for C++?

Discussion in 'C++' started by Paul, Mar 23, 2011.

  1. Paul

    Paul Guest

    <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?
    Paul, Mar 23, 2011
    #1
    1. Advertising

  2. Paul

    SG Guest

    On 23 Mrz., 21:00, "Paul" <> wrote:
    > [...]


    Ask one of the experts whether "an array is just a pointer", come back
    and share their responses with us.

    SG
    SG, Mar 23, 2011
    #2
    1. Advertising

  3. Paul

    Paul Guest

    "Paul" <> wrote in message
    news:pjsip.64405$2...
    > <quote ref: http://c-faq.com/aryptr/aryptr2.html >

    <snip>
    > 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.
    Paul, Mar 23, 2011
    #3
  4. On Mar 23, 3:37 pm, "Paul" <> wrote:
    > 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.)
    Joshua Maurice, Mar 23, 2011
    #4
  5. Paul

    Paul Guest

    "Joshua Maurice" <> wrote in message
    news:...
    On Mar 23, 3:37 pm, "Paul" <> wrote:
    > 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.
    Paul, Mar 23, 2011
    #5
  6. Paul

    Goran Guest

    On Mar 23, 11:37 pm, "Paul" <> wrote:
    > 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.
    Goran, Mar 24, 2011
    #6
  7. Paul

    SG Guest

    On 24 Mrz., 14:13, Goran wrote:
    >
    > 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
    SG, Mar 24, 2011
    #7
  8. Paul

    Paul Guest

    "Goran" <> wrote in message
    news:...
    On Mar 23, 11:37 pm, "Paul" <> wrote:
    > 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.


    <snip>

    >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.
    Paul, Mar 24, 2011
    #8
  9. Paul

    Goran Guest

    On Mar 24, 3:51 pm, "Paul" <> wrote:
    > >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.


    It's one thing to disagree, another to be right. What part of my
    argument is wrong?

    Goran.
    Goran, Mar 25, 2011
    #9
  10. Paul

    Paul Guest

    "Goran" <> wrote in message
    news:...
    On Mar 24, 3:51 pm, "Paul" <> wrote:
    >> >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.

    >
    >It's one thing to disagree, another to be right. What part of my
    >argument is wrong?


    Can't you work that out?
    Paul, Mar 25, 2011
    #10
  11. Paul

    Goran Guest

    On Mar 25, 9:39 am, "Paul" <> wrote:
    > "Goran" <> wrote in message
    >
    > news:...
    > On Mar 24, 3:51 pm, "Paul" <> wrote:
    >
    > >> >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.

    >
    > >It's one thing to disagree, another to be right. What part of my
    > >argument is wrong?

    >
    > Can't you work that out?


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

    Goran.
    Goran, Mar 25, 2011
    #11
  12. Paul

    Paul Guest

    "Goran" <> wrote in message
    news:fc897515-da93-4dc8-867e->
    > >> >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.

    >
    > >It's one thing to disagree, another to be right. What part of my
    > >argument is wrong?

    >
    > Can't you work that out?


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

    Top of page
    Paul, Mar 25, 2011
    #12
  13. Paul

    Goran Guest

    On Mar 25, 3:32 pm, "Paul" <> wrote:
    > "Goran" <> wrote in message
    >
    > news:fc897515-da93-4dc8-867e->
    >
    > > >> >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.

    >
    > > >It's one thing to disagree, another to be right. What part of my
    > > >argument is wrong?

    >
    > > Can't you work that out?

    >
    > --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.
    Goran, Mar 25, 2011
    #13
  14. Paul

    Paul Guest


    >"Goran" <> wrote in message
    >news:...
    >On Mar 25, 3:32 pm, "Paul" <> wrote:
    >> "Goran" <> wrote in message
    >>
    >> news:fc897515-da93-4dc8-867e->
    >>
    >> > >> >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.

    >>
    >> > >It's one thing to disagree, another to be right. What part of my
    >> > >argument is wrong?

    >>
    >> > Can't you work that out?

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

    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.
    Paul, Mar 25, 2011
    #14
  15. Paul

    Drew Lawson Guest

    In article <>
    Goran <> writes:
    >On Mar 25, 3:32 pm, "Paul" <> wrote:
    >> "Goran" <> wrote in message
    >>
    >> --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:


    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.


    --
    |Drew Lawson | Of all the things I've lost |
    | | I miss my mind the most |
    Drew Lawson, Mar 25, 2011
    #15
  16. Paul

    Paul Guest

    "Drew Lawson" <> wrote in message
    news:imirhg$7m4$...
    > In article
    > <>
    > Goran <> writes:
    >>On Mar 25, 3:32 pm, "Paul" <> wrote:
    >>> "Goran" <> wrote in message
    >>>
    >>> --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:

    >
    > 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.
    >
    >
    > --
    > |Drew Lawson | Of all the things I've lost |
    > | | I miss my mind the most |
    >


    Interesting theory.
    You should be an online phycologist, analysing people without even seeing
    them is obviously one of your traits :)
    Paul, Mar 25, 2011
    #16
  17. Paul

    Drew Lawson Guest

    In article <>
    cg_chas <> writes:
    >
    >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.

    --
    Drew Lawson | What you own is your own kingdom
    | What you do is your own glory
    | What you love is your own power
    | What you live is your own story
    Drew Lawson, Mar 26, 2011
    #17
  18. -----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 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-----
    Michael Tsang, Apr 2, 2011
    #18
  19. Paul

    Paul Guest

    "Michael Tsang" <> wrote in message
    news:in7cbh$1sm$...
    > -----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 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.
    Paul, Apr 2, 2011
    #19
  20. Paul

    hanukas Guest

    On Apr 2, 6:15 pm, "Paul" <> wrote:
    > "Michael Tsang" <> wrote in message
    >
    > news:in7cbh$1sm$...
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > > -----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.
    hanukas, Apr 2, 2011
    #20
    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. Salisha Khan
    Replies:
    1
    Views:
    11,651
    JohnFol
    Aug 1, 2003
  2. Replies:
    2
    Views:
    393
  3. Pial
    Replies:
    4
    Views:
    56,706
    Phatman
    Aug 27, 2010
  4. Paul Leventis

    Re: Quartus bug or wrong VHDL?

    Paul Leventis, Jun 24, 2003, in forum: VHDL
    Replies:
    0
    Views:
    2,466
    Paul Leventis
    Jun 24, 2003
  5. Matthew
    Replies:
    7
    Views:
    669
    Priscilla Walmsley
    Jan 7, 2005
Loading...

Share This Page