This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: pointer math vs named address spaces
- From: Joseph Myers <joseph at codesourcery dot com>
- To: DJ Delorie <dj at redhat dot com>
- Cc: <gcc at gcc dot gnu dot org>
- Date: Wed, 3 Dec 2014 22:46:36 +0000
- Subject: Re: pointer math vs named address spaces
- Authentication-results: sourceware.org; auth=none
- References: <201412032234 dot sB3MYEmp030041 at greed dot delorie dot com>
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