Re: prtdiff_t / void *

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux