Can this cast fail and when?
long x=-1;
long y = (long)(void*)x;
assert(x==y);
More specifically, how to detect if the above cast is OK at compile time.
A more portable way (on the C99 standard variant) is to #include <stdint.h>
and then cast pointers to intptr_t
(and back). This integer type is guaranteed to be the size of a pointer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With