pointer math vs named address spaces
Joseph Myers
joseph@codesourcery.com
Wed Dec 3 22:46:00 GMT 2014
On Wed, 3 Dec 2014, DJ Delorie wrote:
> If a target (rl78-elf in my case) has a named address space larger
> than the generic address space (__far in my case), why is pointer math
> in that named address space still truncated to sizetype?
>
> N1275 recognizes that named address spaces might be a different size
> than the generic address space, but I didn't see anything that
> required such truncation.
For adding an integer to a pointer, it's true that logically there should
be no such truncation (or truncation should be only to the width of the
particular pointer rather than a generic pointer).
However, pointer subtraction still returns ptrdiff_t, and sizeof still
returns size_t, and both have undefined behavior if the result is outside
the range of those types, so there are still limits on what you can
usefully do with pointers wider than those types.
--
Joseph S. Myers
joseph@codesourcery.com
More information about the Gcc
mailing list