Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #16655

Re: Pointer Equality for Different Array Objects

From Kaz Kylheku <kaz@kylheku.com>
Newsgroups comp.lang.c
Subject Re: Pointer Equality for Different Array Objects
Date 2012-02-03 07:11 +0000
Organization A noiseless patient Spider
Message-ID <20120202225914.467@kylheku.com> (permalink)
References <jgfa2r$h8h$1@dont-email.me> <20120202163655.24@kylheku.com> <jgfcn5$t4p$1@dont-email.me> <20120202173230.529@kylheku.com> <jgfupa$pn$1@dont-email.me>

Show all headers | View raw


On 2012-02-03, Shao Miller <sha0.miller@gmail.com> wrote:
> But for any stricter run-time bounds-checking, such as catching 
> 'a[i][j]' where the ranges for 'i' and 'j' aren't known at 
> translation-time and go out-of-bounds, there could be checks for each 
> dimension of a multi-dimensional array, but is that consistent with C?

You know, who cares? All that matters is: is this check valuable to the user?
Checks can be stronger or weaker than the standard language.  Suppose that the
C standard explicitly said that an array is just flat memory that can be
aliased with any multi-dimensional array geometry.  Well, someone might still
want some of their code to pass array dimension bounds checks.

> It would seem unfair to give the array subscripting notation 'a[0][3]' 
> some kind of bounds-preferential treatment versus the identical '*(*(a + 
> 0) + 3)' notation.

No, but the preferential treatment could actually stem from the 
"a + displacement" where a is not a pointer, but an array (that converts to a
pointer on evaluation) and not from the choice of notation. 

In such an expression, there is enough info to know that the displacement is in
bounds with respect to the static type of a, regardless of the larger
container in which that array finds itself.

> But we do see references to "provenance" in at least one defect report, 
> and this seems related to the "provenance" of a pointer.  If it "came 
> from" an array with certain boundaries, then pointer arithmetic is only 
> defined for its use with those boundaries, despite the fact that another 
> pointer with difference boundaries is identical in every other way.
>
> Of course "provenance" seems like a "gray area," since you can combine 
> things (such as via bit-wise operators).  Then whence did they come?

Clearly, at some point provenance has to be severed. A good rule of thumb (if
provenance were to stop being a gray area) might be that a pointer value
that is derived from a conversion from array, plus any combination of
displacements, has provenance from that array. As soon as &..*.. is involved,
it should be lost: e.g. &a[0] or &*(a + 0) ought to drop provenance. 

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Pointer Equality for Different Array Objects Shao Miller <sha0.miller@gmail.com> - 2012-02-02 19:34 -0500
  Re: Pointer Equality for Different Array Objects Shao Miller <sha0.miller@gmail.com> - 2012-02-02 19:40 -0500
  Re: Pointer Equality for Different Array Objects Kaz Kylheku <kaz@kylheku.com> - 2012-02-03 00:47 +0000
    Re: Pointer Equality for Different Array Objects Shao Miller <sha0.miller@gmail.com> - 2012-02-02 20:19 -0500
      Re: Pointer Equality for Different Array Objects pete <pfiland@mindspring.com> - 2012-02-02 20:45 -0500
        Re: Pointer Equality for Different Array Objects Shao Miller <sha0.miller@gmail.com> - 2012-02-02 21:15 -0500
        Re: Pointer Equality for Different Array Objects Kaz Kylheku <kaz@kylheku.com> - 2012-02-03 02:36 +0000
      Re: Pointer Equality for Different Array Objects Kaz Kylheku <kaz@kylheku.com> - 2012-02-03 02:35 +0000
        Re: Pointer Equality for Different Array Objects Shao Miller <sha0.miller@gmail.com> - 2012-02-03 01:27 -0500
          Re: Pointer Equality for Different Array Objects Shao Miller <sha0.miller@gmail.com> - 2012-02-03 01:29 -0500
          Re: Pointer Equality for Different Array Objects Kaz Kylheku <kaz@kylheku.com> - 2012-02-03 07:11 +0000
            Re: Pointer Equality for Different Array Objects Shao Miller <sha0.miller@gmail.com> - 2012-02-03 19:31 -0500
  Re: Pointer Equality for Different Array Objects Shao Miller <sha0.miller@gmail.com> - 2012-02-06 02:25 -0500

csiph-web