-
David Gibson authored
For callbacks which need a void * context pointer in the general case, there are often simpler cases where an integer would suffice. These are often handled by casting the integer into a pointer, rather than having to allocate that integer somewhere. This adds a module with some helpers for this. It has some advantages over direct casts: * It uses pointer arithmetic against NULL instead of casts which should make it more portable, even to weird platforms with odd representations for NULL. I don't know the C standard well enough to know if it's totally portable though. * In particular it means that the truth value of the pointer representation matches that of the encoded integer. * The conversion functions are inlines providing more type safety than raw casts. * It uses a ptrint_t * type which can be used to mark such pointer encoded integers. ptrint_t is a deliberately incomplete type so such pointers can never be dereferenced. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
53079b9c