This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: prtdiff_t / void *
- From: Martin Sebor <msebor at gmail dot com>
- To: Toebs Douglass <toby at winterflaw dot net>, "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Sun, 13 Aug 2017 12:12:46 -0600
- Subject: Re: prtdiff_t / void *
- Authentication-results: sourceware.org; auth=none
- References: <bc4280eb-e4c6-7f53-4cf2-6229b566385d@winterflaw.net>
On 08/13/2017 05:41 AM, Toebs Douglass wrote:
Is it reasonable to assume a ptrdiff_t can be stored in a void * on the
vast majority of platforms supported by GCC?
Are there any known cases where ptrdiff_t isn't just a signed int, but
actually is a special, magic type?
Searching GCC headers for the POINTER_SIZE and PTRDIFF_TYPE macros
should help answer the question (but see below). I see just one
special type that's not signed int, though I'm not sure I'd call
it magic. The msp430 targets (config/msp430/msp430.h) conditionally
defines PTRDIFF_TYPE to be __int20, but it also defines POINTER_SIZE
to 20.
That said, I don't know if the same size is necessarily a guarantee
that an arbitrary ptrdiff_t value can be stored in a void* on all
supported targets. C makes it possible for a target to trap when
a bit pattern that doesn't correspond to a valid pointer value is
stored in an object of pointer type.
Martin