Re: Example in Docs: GPOINTER_TO_INT



On Friday, July 27, 2001, at 09:54  AM, Dmitry Ponomaryov wrote:

What does "but storing a pointer in an integer will not work" here mean?
Macros GPOINTER_TO_INT(p) is `#define GPOINTER_TO_INT(p) ((gint)
${glib_gpi_cast} (p))`
and `glib_gpi_cast` is empty ''" or glong.
So it always works! but may return ugly rezult. Am I right?

GPOINTER_TO_INT is guaranteed to convert an integer back if it was changed to a pointer with GINT_TO_POINTER. But if the pointer was not made by GINT_TO_POINTER, there's no guarantee it will fit in an integer. On some platforms, pointers may be 64 bits while integers are 32 bits.

So we use GINT_TO_POINTER to store integers are pointers, and then use GPOINTER_TO_INT to get the integer back. But we can't use GPOINTER_TO_INT to change an arbitrary pointer into an integer and expect to be able to get the pointer back with GINT_TO_POINTER. That will work on many systems,
 but it's not guaranteed to work on all of them.

    -- Darin




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]