GLib Reference Manual | |||
---|---|---|---|
<<< Previous Page | Home | Up | Next Page >>> |
#include <glib.h> #define GINT_TO_POINTER (i) #define GPOINTER_TO_INT (p) #define GUINT_TO_POINTER (u) #define GPOINTER_TO_UINT (p) |
These macros provide a portable method of storing gint and guint values in gpointer variables.
Many of the GLib data types are based on storing gpointer values, e.g. GHashTable, GList, GSList, GTree, and GNode. By using the type conversion macros described below you can store gint and guint values inside a gpointer. So you can, for example, create a hash table of gint values, or a linked list of guint values.
The type conversion macros are necessary because the size of a gpointer can vary across different platforms. So the type conversion has to be done carefully.
Note that the reverse operation, storing gpointer values in integer variables, is not supported, since an integer is not guaranteed to be large enough to store gpointer values across all platforms.
To convert an integer value, a gint, to a gpointer, use GINT_TO_POINTER. To convert it back to a gint, use GPOINTER_TO_INT.
To convert an unsigned integer, a guint, to a gpointer, use GUINT_TO_POINTER. To convert it back to a guint, use GPOINTER_TO_UINT.