Re: well-defined terminology versus generally accepted terminologyregarding pointers and arrays

Discussion in 'C++' started by Ian Collins, Apr 13, 2011.

  1. Ian Collins

    Ian Collins Guest

    On 04/14/11 12:27 AM, cg_chas wrote:
    > Needless to say, there is significant dissension regarding when, or even if, it
    > is ever preferrable to use well-defined terminology instead of loose or casual
    > but generally accepted terminology regarding pointers and arrays.
    >
    > Examples such as:
    > int a[42];
    > int* p2 = a;
    > apparently create huge debates about how to describe the above expressions.
    >
    > Similar examples include expressions like:
    > int* p1 = new int[42];
    >
    > I gleen two cases representing the major divisions of opinion in this matter and
    > I happen to not agree entirely with either.
    >
    > 1) Nobody is actually saying that the int pointers p1 and p2 do not point to the
    > initial element of an array, but more than one has expressed that it is silly to
    > put it that way.
    >
    > 2) More than one has said that it is "generally acceptable" to say that the
    > above expressions are both int pointers that point to arrays.


    One point I don't think has been argued over: when is an array not an
    array?

    If after int* p1 = new int[42]; p pints to an array, what does ++p point
    to? Another array? If p is a pointer to an array, does incrementing p
    change it to something else?

    The standard is unambiguous as to what p is:

    5.3.4/1:

    "If it is an array, the new-expression returns a pointer
    to the initial element of the array."

    and what p2 above is:

    4.2/1:

    "An lvalue or rvalue of type “array of N T” or “array of unknown bound
    of T” can be converted to an rvalue of type “pointer to T.” The result
    is a pointer to the first element of the array."

    > My thoughts are:
    >
    > In any C++ discussion about pointer to T, is it really ever silly to say that an
    > int* points to the initial element of an array of int when it is well-defined to
    > do so?
    > No.
    >
    > It is not silly because widely recognized C++ sources say it just that way.
    > 1) The C++ Programming Language, Bjarne Stroustrup section 5.3 Pointers into
    > Arrays
    > 2) Accelerated C++, Andrew Koenig 10.1.3 Arrays (last paragraph, second
    > sentence)
    > 3) ISO/IEC 14882 5.3.4 New (paragraph 1, last two senctences)
    >
    > In any C++ discussion about pointer to T, is what is claimed to be "generally
    > acceptable" (the statement that an int* points to an array) ever truly
    > technically correct?
    > No.
    >
    > If the discussion is about "pointer to T" then it is both inaccurate and
    > irresponsible to say that an int* points to an array. Only in the most casual
    > and general sense is this statement acceptable and only when the discussion is
    > not about "pointer to T".


    I agree.

    --
    Ian Collins
    Ian Collins, Apr 13, 2011
    #1
    1. Advertising

  2. * Ian Collins, on 13.04.2011 23:37:
    >
    > One point I don't think has been argued over: when is an array not an array?


    One can possibly say that an array of zero size is not an array.

    Such an array (or non-array?) can only be allocated dynamically.


    > If after int* p1 = new int[42]; p pints to an array, what does ++p point to?
    > Another array? If p is a pointer to an array, does incrementing p change it to
    > something else?


    You're confusing/conflating two levels of formality, so to speak.

    Another example of that: a small heap plus a little grain of sand is still
    small, and so on...

    If you want a reasonable way to think about it, then (new int[42])+1 points into
    an array, and it also points to the start of a sub-array.


    > The standard is unambiguous as to what p is:
    >
    > 5.3.4/1:
    >
    > "If it is an array, the new-expression returns a pointer
    > to the initial element of the array."


    That's quite a bit ambiguous, for what is the first element of the array when
    the array is of zero size?

    But it doesn't really matter.

    I only point that out so that you can see that discussing number of angels here,
    and so forth, is of no practical value whatsoever. Intelligence must be applied.
    And then, with some intelligence, nobody cares about them angels. ;-)


    > and what p2 above is:
    >
    > 4.2/1:
    >
    > "An lvalue or rvalue of type “array of N T” or “array of unknown bound of T” can
    > be converted to an rvalue of type “pointer to T.” The result is a pointer to the
    > first element of the array."
    >
    >> My thoughts are:
    >>
    >> In any C++ discussion about pointer to T, is it really ever silly to say that an
    >> int* points to the initial element of an array of int when it is well-defined to
    >> do so?
    >> No.
    >>
    >> It is not silly because widely recognized C++ sources say it just that way.
    >> 1) The C++ Programming Language, Bjarne Stroustrup section 5.3 Pointers into
    >> Arrays
    >> 2) Accelerated C++, Andrew Koenig 10.1.3 Arrays (last paragraph, second
    >> sentence)
    >> 3) ISO/IEC 14882 5.3.4 New (paragraph 1, last two senctences)
    >>
    >> In any C++ discussion about pointer to T, is what is claimed to be "generally
    >> acceptable" (the statement that an int* points to an array) ever truly
    >> technically correct?
    >> No.
    >>
    >> If the discussion is about "pointer to T" then it is both inaccurate and
    >> irresponsible to say that an int* points to an array. Only in the most casual
    >> and general sense is this statement acceptable and only when the discussion is
    >> not about "pointer to T".

    >
    > I agree.


    Oh, you shouldn't agree to such glib conclusions about nonsense, no matter how
    well formulated.

    It's what we in the old days called techno-babble.

    Not that it hurts very much to agree to any single such, but the cumulative
    effect of techno-babble may at some point be that meaningful communication
    becomes impossible (and I think that that effect has hindered the
    standardization process, but that's just my not even well-informed opinion).


    Cheers & hth.,

    - Alf

    --
    blog at <url: http://alfps.wordpress.com>
    Alf P. Steinbach /Usenet, Apr 13, 2011
    #2
    1. Advertising

  3. * cg_chas, on 14.04.2011 00:19:
    >>>>
    >>>> If the discussion is about "pointer to T" then it is both inaccurate and
    >>>> irresponsible to say that an int* points to an array. Only in the most casual
    >>>> and general sense is this statement acceptable and only when the discussion is
    >>>> not about "pointer to T".
    >>>
    >>> I agree.

    >>
    >> Oh, you shouldn't agree to such glib conclusions about nonsense, no matter how
    >> well formulated.
    >> It's what we in the old days called techno-babble.

    > Well at least now we know how you really feel about technical correctness.


    If you feel that you are several persons, then I suggest seeing a doctor.

    Otherwise, who are the "we" that you pretend to talk for?

    Regarding technical correctness, that you have some trouble understanding common
    expressions in C and C++ programming does not mean that those who do understand
    those expressions have a less clear understanding than you.

    On the contrary.

    IMHO it is far more probable that those who do not understand the common
    terminology, are those lacking in correct understanding.


    Cheers & hth.,

    - Alf

    --
    blog at <url: http://alfps.wordpress.com>
    Alf P. Steinbach /Usenet, Apr 13, 2011
    #3
  4. Ian Collins

    Ian Collins Guest

    On 04/14/11 09:52 AM, Alf P. Steinbach /Usenet wrote:
    > * Ian Collins, on 13.04.2011 23:37:
    >>
    >> One point I don't think has been argued over: when is an array not an
    >> array?

    >
    > One can possibly say that an array of zero size is not an array.
    >
    > Such an array (or non-array?) can only be allocated dynamically.
    >
    >
    >> If after int* p1 = new int[42]; p pints to an array, what does ++p
    >> point to?
    >> Another array? If p is a pointer to an array, does incrementing p
    >> change it to
    >> something else?

    >
    > You're confusing/conflating two levels of formality, so to speak.


    I don't think so.

    > Another example of that: a small heap plus a little grain of sand is
    > still small, and so on...
    >
    > If you want a reasonable way to think about it, then (new int[42])+1
    > points into an array, and it also points to the start of a sub-array.


    Alf, you are inventing new shovels to dig yourself out of a hole!

    >> The standard is unambiguous as to what p is:
    >>
    >> 5.3.4/1:
    >>
    >> "If it is an array, the new-expression returns a pointer
    >> to the initial element of the array."

    >
    > That's quite a bit ambiguous, for what is the first element of the array
    > when the array is of zero size?
    >
    > But it doesn't really matter.
    >
    > I only point that out so that you can see that discussing number of
    > angels here, and so forth, is of no practical value whatsoever.
    > Intelligence must be applied. And then, with some intelligence, nobody
    > cares about them angels. ;-)


    :)

    --
    Ian Collins
    Ian Collins, Apr 13, 2011
    #4
  5. * Ian Collins, on 14.04.2011 00:32:
    > On 04/14/11 09:52 AM, Alf P. Steinbach /Usenet wrote:
    >> * Ian Collins, on 13.04.2011 23:37:
    >>>
    >>> One point I don't think has been argued over: when is an array not an
    >>> array?

    >>
    >> One can possibly say that an array of zero size is not an array.
    >>
    >> Such an array (or non-array?) can only be allocated dynamically.
    >>
    >>
    >>> If after int* p1 = new int[42]; p pints to an array, what does ++p
    >>> point to?
    >>> Another array? If p is a pointer to an array, does incrementing p
    >>> change it to
    >>> something else?

    >>
    >> You're confusing/conflating two levels of formality, so to speak.

    >
    > I don't think so.


    Think again, then. You are. Conflating. The formal and the informal.


    >> Another example of that: a small heap plus a little grain of sand is
    >> still small, and so on...
    >>
    >> If you want a reasonable way to think about it, then (new int[42])+1
    >> points into an array, and it also points to the start of a sub-array.

    >
    > Alf, you are inventing new shovels to dig yourself out of a hole!


    No, you were digging yourself into a hole.

    And you asked, how do I get out?

    I just gave you several means.

    Of course, if you think the ladder is too disgusting old-fashioned to handle,
    then that's your choice.

    But I think at least, after yelling for help, you could say "thanks!" or
    something, instead of bitching about your feelings about the ladder you got
    (bah, old-fashioned), and what person could give you that crappy old ladder.


    >>> The standard is unambiguous as to what p is:
    >>>
    >>> 5.3.4/1:
    >>>
    >>> "If it is an array, the new-expression returns a pointer
    >>> to the initial element of the array."

    >>
    >> That's quite a bit ambiguous, for what is the first element of the array
    >> when the array is of zero size?
    >>
    >> But it doesn't really matter.
    >>
    >> I only point that out so that you can see that discussing number of
    >> angels here, and so forth, is of no practical value whatsoever.
    >> Intelligence must be applied. And then, with some intelligence, nobody
    >> cares about them angels. ;-)

    >
    > :)


    Yes, I think this is the crux.

    That one should be able to assume some intelligence and reasonable
    interpretation, except in some very few contexts (e.g. very formal).

    Cheers & hth.,

    - Alf

    --
    blog at <url: http://alfps.wordpress.com>
    Alf P. Steinbach /Usenet, Apr 13, 2011
    #5
  6. Ian Collins

    Ian Collins Guest

    On 04/14/11 10:45 AM, Alf P. Steinbach /Usenet wrote:
    > * Ian Collins, on 14.04.2011 00:32:
    >> On 04/14/11 09:52 AM, Alf P. Steinbach /Usenet wrote:
    >>> * Ian Collins, on 13.04.2011 23:37:
    >>>>
    >>>> One point I don't think has been argued over: when is an array not an
    >>>> array?
    >>>
    >>> One can possibly say that an array of zero size is not an array.
    >>>
    >>> Such an array (or non-array?) can only be allocated dynamically.
    >>>
    >>>
    >>>> If after int* p1 = new int[42]; p pints to an array, what does ++p
    >>>> point to?
    >>>> Another array? If p is a pointer to an array, does incrementing p
    >>>> change it to
    >>>> something else?
    >>>
    >>> You're confusing/conflating two levels of formality, so to speak.

    >>
    >> I don't think so.

    >
    > Think again, then. You are. Conflating. The formal and the informal.


    OK, fair point.

    >>> Another example of that: a small heap plus a little grain of sand is
    >>> still small, and so on...
    >>>
    >>> If you want a reasonable way to think about it, then (new int[42])+1
    >>> points into an array, and it also points to the start of a sub-array.

    >>
    >> Alf, you are inventing new shovels to dig yourself out of a hole!

    >
    > No, you were digging yourself into a hole.


    Believe me, after recent dramatic events around here (home), I have
    plenty of experience of holes and digging!

    --
    Ian Collins
    Ian Collins, Apr 13, 2011
    #6
  7. Ian Collins

    Noah Roberts Guest

    On 4/13/2011 2:41 PM, cg_chas wrote:
    > On Thu, 14 Apr 2011 09:37:13 +1200, Ian Collins<> wrote:
    >
    >> On 04/14/11 12:27 AM, cg_chas wrote:
    >>> Needless to say, there is significant dissension regarding when, or even if, it
    >>> is ever preferrable to use well-defined terminology instead of loose or casual
    >>> but generally accepted terminology regarding pointers and arrays.
    >>>
    >>> Examples such as:
    >>> int a[42];
    >>> int* p2 = a;
    >>> apparently create huge debates about how to describe the above expressions.
    >>>
    >>> Similar examples include expressions like:
    >>> int* p1 = new int[42];
    >>>
    >>> I gleen two cases representing the major divisions of opinion in this matter and
    >>> I happen to not agree entirely with either.
    >>>
    >>> 1) Nobody is actually saying that the int pointers p1 and p2 do not point to the
    >>> initial element of an array, but more than one has expressed that it is silly to
    >>> put it that way.
    >>>
    >>> 2) More than one has said that it is "generally acceptable" to say that the
    >>> above expressions are both int pointers that point to arrays.

    >>
    >> One point I don't think has been argued over: when is an array not an
    >> array?
    >>
    >> If after int* p1 = new int[42]; p pints to an array, what does ++p point
    >> to? Another array? If p is a pointer to an array, does incrementing p
    >> change it to something else?

    > I am guessing Alf would say a "sub-object" or "sub-array".
    > In either case, as soon as we start incrementing the pointer or the topic of
    > discussion is about "pointer to T" which incrementing implies, then I would
    > assert that "p points to an array" was technically imprecise and that p points
    > to an element of an array now and before incrementing.


    Hopefully not, because there's numerous problems with such a definition.
    For example, passing a pointer that "points to" (as they're defining
    it here) an array to "delete []" works...the same would NOT work with a
    "sub-array".

    At this point I believe its better to continue holding true to the
    concept of pointer as distinct to iterator. A pointer points at AN
    object. An iterator is a refinement of pointer that also allows
    iteration over a container (and in the subject of discussion that
    container is an array). Thus both p1 and p2 are pointers to elements in
    an array that are also iterators for that array. These terms are not
    interchangeable, one refines the other.

    --
    http://crazycpp.wordpress.com
    Noah Roberts, Apr 14, 2011
    #7
  8. Ian Collins

    Noah Roberts Guest

    On 4/13/2011 3:19 PM, cg_chas wrote:
    > On Wed, 13 Apr 2011 23:52:41 +0200, "Alf P. Steinbach /Usenet"
    >> It's what we in the old days called techno-babble.

    > Well at least now we know how you really feel about technical correctness.
    > Truth begets truth as they say.


    My recollection of the term "techno-babble" is that it is/was most
    commonly used by people that resented the fact that they didn't
    understand the tech, similarly to how "elitist" is now a word used to
    describe the educated by dropouts.

    --
    http://crazycpp.wordpress.com
    Noah Roberts, Apr 14, 2011
    #8
  9. * cg_chas, on 14.04.2011 01:21:
    >
    > The fact that you consider it to be techno-babble is poor judgment on your part
    > given that you have repeatedly refused to answer the most simple and direct
    > questions regarding statements that you have made.


    I'm sorry, but I'm not aware of any such questions.


    > you purposefully cling to the most inane cases and exceptions that
    > apparently in your mind some how makes the actual context of a discussion
    > irrelevant.


    That's at best a misguided impression, expressed in the vaguest of terms. I have
    no idea what concrete things your are talking about. If any.


    > And you do so instead of simply conceding the fact that there are numerous
    > scenarios where being technically precise would lead to greater productivity
    > than being irresponsible and technically imprecise.


    I'm sorry to say this, but that's a lie.

    That means, you know that it's false but you try to make others believe it.

    Other readers may think about e.g. my writing the "correct" C++ tutorial
    referenced in FAQ item 29.21. It's now off-net, but when I wrote it it was in
    response to all the technically imprecise and incorrect information then on the
    net. I think that that's not the thing a person who is irresponsibly hooked on
    the technically imprecise, would do.


    Cheers & hth.,

    - Alf

    --
    blog at <url: http://alfps.wordpress.com>
    Alf P. Steinbach /Usenet, Apr 14, 2011
    #9
  10. * cg_chas, on 14.04.2011 05:12:
    > On Thu, 14 Apr 2011 03:11:49 +0200, "Alf P. Steinbach /Usenet"
    > <> wrote:

    [snip trolling]
    >
    >
    > Alf said,
    > " 3) And a pointer of type T* be said to point to an array of T, but only
    > in the dynamic sense, like "right now it points to an array".
    >
    > I ask this rhetorically because due to the degraded nature of the discussion:
    >
    > How sensible is it really to use the fact that "pointers of C++ are
    > well-defined, with almost no ambiguity" as the supporting logic for a clearly
    > undefined definition that you have presented as your dynamic case (3) ?


    As far as I understand it you're asking, how sensible is the common terminology
    where a pointer is said to point to an array when it points to an array?

    Well, it works nicely in practice.

    I'm not sure what you mean by "supporting logic", but if you're wondering why I
    remarked on definedness of terms, that was because it illustrates that even
    among experts there are differences of opinion about basic terminology (as I
    stated), and if you're wondering why I narrowed things down to raw pointers,
    that was because it's easier to discuss things in a limited, clear context.


    > In effect what you have said in a round about way is, "pointers are well-defined
    > and unambiguous in the C++ world" so this is why it is ok and generally
    > acceptable to say that "right now an int* points to an array"


    No, I have not said that; your "this is why" is at best a misconception.

    It's OK to say, informally, that e.g. a 'char const*' points to a string (if it
    does), because any C++ programmer understands it.

    And it's the common way to talk about it. You never say "points to the first
    char of a string" except when you explain the concept of pointing or there is a
    possibility of pointing to, say, the second char. In short, one does not
    normally specify something that is the default, and that is taken for granted.


    > You claimed above that I am false but make others try to believe something.
    >
    > I claim that you are using a truth completely out of context to support your
    > case that has absolutely no truth when held up to an actual well-defined pointer
    > definition. That makes you the deceiver, not me.


    I can't make head or tail of statement, sorry.

    But in conclusion, you started nicely in this thread, but have degraded seriously.

    I do not much like person-fixation here. Of your long tirade only one paragraph
    (second quote upwards from here) was about any halfway concrete issue. The rest,
    which I chose to snip, was about me, focusing on person only.


    Cheers,

    - Alf

    --
    blog at <url: http://alfps.wordpress.com>
    Alf P. Steinbach /Usenet, Apr 14, 2011
    #10
    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. Alf P. Steinbach /Usenet
    Replies:
    61
    Views:
    1,000
  2. SG
    Replies:
    4
    Views:
    261
    Peter Remmers
    Apr 14, 2011
  3. Paul
    Replies:
    63
    Views:
    1,207
  4. Paul Butcher
    Replies:
    12
    Views:
    685
    Gary Wright
    Nov 28, 2007
  5. Thufir
    Replies:
    8
    Views:
    166
    Robert Dober
    Oct 24, 2007
Loading...

Share This Page