|
Can you explain this code ? #define UMWFromPointer(Pointer) ((umw)(Pointer))
#define PointerFromUMW(type, Value) (type *)(Value) |
Replies: 1 comment
|
That type umw is an unsigned machine word. It's an alias for There are also 2 macros there that will get an umw from a Pointer or give a pointer to a certain type from a given UMW.
Why do this at all? Sometimes an int field can be useful for storing a pointer especially when interfacing with OS APIs. |
That type umw is an unsigned machine word. It's an alias for
uintptr_twhich is an unsigned int type that is guaranteed to be able to hold a pointer without losing any bits.There are also 2 macros there that will get an umw from a Pointer or give a pointer to a certain type from a given UMW.
UMWFromPointer(Pointer), this converts a pointer into an integer that is large enough to hold it.So, what you get is a numerical representation of the pointer that you pass to it.
PointerFromUMW(type, Value), this takes an integer like one created fromUMWFromPointer(Pointer)and cast it back into a pointer of typetype.So, Value would be a UMW (an unsigned machine word)
Why do this at all? Sometim…