On 13/08/17 20:12, Martin Sebor wrote:
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 have no idea why I didn't think of this!
Turns out then I have to thank you for doing work I should have done
myself. Thankyou!
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.
Right.
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.
I do not properly understand that final sentence.
I understand what it means in general, but I'm surprised by that it can
happen; I've not heard of it before. To make sure I understand - this
is a kind of run-time error, like divide by zero?