This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PR 25512: pointer overflow defined?


Robert Dewar <dewar@adacore.com> writes:

| Richard Guenther wrote:
| 
| >On Wed, 21 Dec 2005, Andrew Haley wrote:
| >
| >
| >>Richard Guenther writes:
| >> > > The problem in this PR is that code like in the testcase (from
| >> > OpenOffice) assumes that pointer overflow is defined.  As the
| >> > standard does not talk about wrapping pointer semantics at all (at
| >> > least I couldn't find anything about that), how should we treat
| >> > this?
| >>
| >>Look at Section 6.5.6, Para 8.  The code is undefined.
| >>
| >
| >This talks about pointers that point to elements of an array object.
| >It does not talk about doing arithmetic on arbitrary pointer (constants),
| >which is what the code does.
| >
| Right, but that's the point. "doing arithmetic on arbitrary pointer"
| values is
| not defined, 

I think that needs qualification, given the semantics of 

  pointer -> integer type
  integer type -> pointer

conversions.

|it is not even defined to compare two pointers pointing to two
| different objects.

you can (equality) compare a pointer to NULL -- which does not even
happen to designate an object.

[...]

| One way to think about the semantic model is to consider pointers
| in C to consist of a base/offset pair, where the base points to the
| start of the object (some debugging checkout C compilers even
| use such a format). Then operations on pointers need ONLY
| reference the offset.

that model is too simplistic -- hint: null pointers.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]