From: Mike McCarty (jmccarty_at_ssd.usa.alcatel.com)
Date: 2001-05-25 15:21:49
On Fri, 25 May 2001, Mark Keates wrote:
> Hi,
>
> > In addition, ANSI disallows calculating pointers that
> > point outside of objects, so your code is not standard
> > compliant anyway.
>
> True, just me being lazy I guess, I have a multi segment
[snip]
Not completely true. ANSI allows calculating pointers which point one
element past the end of an array.
I quote the Standard
6.3.6 Additive operators
...
Moreover, if the expression P points to the last element of an
array object, the expression (P)+1 points one past the last
element of the array object, and if the expression Q points one
past the last element of an array object, the expression (Q)-1
points to the last element of the object.
...
[When subtracting one pointer from another] Unless both
pointers point to elements of the same array object, or one
past the last element of the array object, the behavior is
undefined. [footnote 46: Another way to approach pointer
arithmetic is first to convert the pointer(s) to character
pointer(s): In this scheme the integral expression added to or
subtracted from the converted pointer is first multiplied by
the size of the object originally pointed to, and the resulting
pointer is converted back to the original type. For pointer
subtraction, the result of the difference between the original
character pointers is similarly divided by the size of the
object originally pointed to.
When viewed in this way, an implementation need only provide
one extra byte (which may overlap another object in the
program) just after the end of the object in order to satisfy
the "one past the last element" requirements.]
Similar language occurs multiple times in the Standard.
I realize that this may not apply in your circumstance (for some
reason, this is the first message on this topic I have seen, others did
not reach me), but it is important for understanding how the language
works.
Mike
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:40 CET