Initial revision
[platform/upstream/glib.git] / docs / reference / glib / tmpl / type_conversion.sgml
1 <!-- ##### SECTION Title ##### -->
2 Type Conversion Macros
3
4 <!-- ##### SECTION Short_Description ##### -->
5 a portable method for storing #gint &amp; #guint values in #gpointer variables.
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
9 These macros provide a portable method of storing #gint and #guint values in
10 #gpointer variables.
11 </para>
12 <para>
13 Many of the GLib data types are based on storing #gpointer values,
14 e.g. #GHashTable, #GList, #GSList, #GTree, and #GNode.
15 By using the type conversion macros described below you can store #gint and
16 #guint values inside a #gpointer. So you can, for example, create
17 a hash table of #gint values, or a linked list of #guint values.
18 </para>
19 <para>
20 The type conversion macros are necessary because the size of a #gpointer can
21 vary across different platforms. So the type conversion has to be done
22 carefully.
23 </para>
24 <para>
25 Note that the reverse operation, storing #gpointer values in
26 integer variables, is not supported, since an integer is not guaranteed to
27 be large enough to store #gpointer values across all platforms.
28 </para>
29 <para>
30 To convert an integer value, a #gint, to a #gpointer, use #GINT_TO_POINTER.
31 To convert it back to a #gint, use #GPOINTER_TO_INT.
32 </para>
33 <para>
34 To convert an unsigned integer, a #guint, to a #gpointer, use
35 #GUINT_TO_POINTER. To convert it back to a #guint, use #GPOINTER_TO_UINT.
36 </para>
37
38 <!-- ##### SECTION See_Also ##### -->
39 <para>
40
41 </para>
42
43 <!-- ##### MACRO GINT_TO_POINTER ##### -->
44 <para>
45 Converts a #gint to a #gpointer.
46 </para>
47
48 @i: a #gint value.
49 @Returns: the value converted to a #gpointer.
50
51
52 <!-- ##### MACRO GPOINTER_TO_INT ##### -->
53 <para>
54 Converts a #gpointer to a #gint.
55 </para>
56
57 @p: a #gpointer value.
58 @Returns: the value converted to a #gint.
59
60
61 <!-- ##### MACRO GUINT_TO_POINTER ##### -->
62 <para>
63 Converts a #guint to a #gpointer.
64 </para>
65
66 @u: a #guint value.
67 @Returns: the value converted to a #gpointer.
68
69
70 <!-- ##### MACRO GPOINTER_TO_UINT ##### -->
71 <para>
72 Converts a #gpointer to a #guint.
73 </para>
74
75 @p: a #gpointer value.
76 @Returns: the value converted to a #guint.
77
78