1 /* CC0 (Public domain) - see LICENSE file for details */
9 #include <ccan/build_assert/build_assert.h>
12 * This is a deliberately incomplete type, because it should never be
13 * dereferenced - instead it marks pointer values which are actually
16 typedef struct ptrint ptrint_t;
18 static inline ptrdiff_t ptr2int(const ptrint_t *p)
21 * ptrdiff_t is the right size by definition, but to avoid
22 * surprises we want a warning if the user can't fit at least
23 * a regular int in there
25 BUILD_ASSERT(sizeof(int) <= sizeof(ptrdiff_t));
26 return (const char *)p - (const char *)NULL;
29 static inline ptrint_t *int2ptr(ptrdiff_t i)
31 return (ptrint_t *)((char *)NULL + i);
34 #endif /* CCAN_PTRINT_H */