![]() | ![]() | ![]() | GLib Reference Manual | ![]() |
---|
Type Conversion Macros — portably storing integers in pointer variables.
#include <glib.h> #define GINT_TO_POINTER (i) #define GPOINTER_TO_INT (p) #define GUINT_TO_POINTER (u) #define GPOINTER_TO_UINT (p) #define GSIZE_TO_POINTER (s) #define GPOINTER_TO_SIZE (p)
int *ip = g_new (int, 1); *ip = 42;
gpointer p; int i; p = (void*) 42; i = (int) p;
gpointer p; int i; p = (void*) (long) 42; i = (int) (long) p;
YOU MAY NOT STORE POINTERS IN INTEGERS. THIS IS NOT PORTABLE IN ANY WAY SHAPE OR FORM. These macros ONLY allow storing integers in pointers, and only preserve 32 bits of the integer; values outside the range of a 32-bit integer will be mangled.
#define GINT_TO_POINTER(i) ((gpointer) (i))
Stuffs an integer into a pointer type.
Remember, YOU MAY NOT STORE POINTERS IN INTEGERS. THIS IS NOT PORTABLE IN ANY WAY SHAPE OR FORM. These macros ONLY allow storing integers in pointers, and only preserve 32 bits of the integer; values outside the range of a 32-bit integer will be mangled.
i : | integer to stuff into a pointer. |
#define GPOINTER_TO_INT(p) ((gint) (p))
Extracts an integer from a pointer. The integer must have been stored in the pointer with GINT_TO_POINTER().
Remember, YOU MAY NOT STORE POINTERS IN INTEGERS. THIS IS NOT PORTABLE IN ANY WAY SHAPE OR FORM. These macros ONLY allow storing integers in pointers, and only preserve 32 bits of the integer; values outside the range of a 32-bit integer will be mangled.
p : | pointer containing an integer. |
#define GUINT_TO_POINTER(u) ((gpointer) (u))
Stuffs an unsigned integer into a pointer type.
u : | unsigned integer to stuff into the pointer. |
#define GPOINTER_TO_UINT(p) ((guint) (p))
Extracts an unsigned integer from a pointer. The integer must have been stored in the pointer with GUINT_TO_POINTER().
p : | pointer to extract an unsigned integer from. |
#define GSIZE_TO_POINTER(s) ((gpointer) (gsize) (s))
Stuffs a gsize into a pointer type.
s : | gsize to stuff into the pointer. |
#define GPOINTER_TO_SIZE(p) ((gsize) (p))
Extracts a gsize from a pointer. The gsize must have been stored in the pointer with GSIZE_TO_POINTER().
p : | pointer to extract a gsize from. |
<< Standard Macros | Byte Order Macros >> |