<refentry id="glib-Basic-Types">
<refmeta>
<refentrytitle role="top_of_page" id="glib-Basic-Types.top_of_page">Basic Types</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GLIB Library</refmiscinfo>
</refmeta>

<refnamediv>
<refname>Basic Types</refname>
<refpurpose>standard GLib types, defined for ease-of-use and portability</refpurpose>
</refnamediv>

<refsynopsisdiv id="glib-Basic-Types.synopsis" role="synopsis">
<title role="synopsis.title">Synopsis</title>

<synopsis>

#include &lt;glib.h&gt;

typedef             <link linkend="gboolean">gboolean</link>;
typedef             <link linkend="gpointer">gpointer</link>;
typedef             <link linkend="gconstpointer">gconstpointer</link>;
typedef             <link linkend="gchar">gchar</link>;
typedef             <link linkend="guchar">guchar</link>;

typedef             <link linkend="gint">gint</link>;
typedef             <link linkend="guint">guint</link>;
typedef             <link linkend="gshort">gshort</link>;
typedef             <link linkend="gushort">gushort</link>;
typedef             <link linkend="glong">glong</link>;
typedef             <link linkend="gulong">gulong</link>;

typedef             <link linkend="gint8">gint8</link>;
typedef             <link linkend="guint8">guint8</link>;
typedef             <link linkend="gint16">gint16</link>;
typedef             <link linkend="guint16">guint16</link>;
typedef             <link linkend="gint32">gint32</link>;
typedef             <link linkend="guint32">guint32</link>;

#define             <link linkend="G-HAVE-GINT64--CAPS">G_HAVE_GINT64</link>
typedef             <link linkend="gint64">gint64</link>;
typedef             <link linkend="guint64">guint64</link>;
#define             <link linkend="G-GINT64-CONSTANT--CAPS">G_GINT64_CONSTANT</link>                   (val)
#define             <link linkend="G-GUINT64-CONSTANT--CAPS">G_GUINT64_CONSTANT</link>                  (val)

typedef             <link linkend="gfloat">gfloat</link>;
typedef             <link linkend="gdouble">gdouble</link>;

typedef             <link linkend="gsize">gsize</link>;
typedef             <link linkend="gssize">gssize</link>;
typedef             <link linkend="goffset">goffset</link>;
#define             <link linkend="G-GOFFSET-CONSTANT--CAPS">G_GOFFSET_CONSTANT</link>                  (val)

typedef             <link linkend="gintptr">gintptr</link>;
typedef             <link linkend="guintptr">guintptr</link>;
</synopsis>
</refsynopsisdiv>









<refsect1 id="glib-Basic-Types.description" role="desc">
<title role="desc.title">Description</title>
<para>
GLib defines a number of commonly used types, which can be divided into
4 groups:
<itemizedlist>
<listitem><para>
New types which are not part of standard C - <link linkend="gboolean"><type>gboolean</type></link>, <link linkend="gsize"><type>gsize</type></link>, <link linkend="gssize"><type>gssize</type></link>.
</para></listitem>
<listitem><para>
Integer types which are guaranteed to be the same size across all platforms -
<link linkend="gint8"><type>gint8</type></link>, <link linkend="guint8"><type>guint8</type></link>, <link linkend="gint16"><type>gint16</type></link>, <link linkend="guint16"><type>guint16</type></link>, <link linkend="gint32"><type>gint32</type></link>, <link linkend="guint32"><type>guint32</type></link>, <link linkend="gint64"><type>gint64</type></link>, <link linkend="guint64"><type>guint64</type></link>.
</para></listitem>
<listitem><para>
Types which are easier to use than their standard C counterparts -
<link linkend="gpointer"><type>gpointer</type></link>, <link linkend="gconstpointer"><type>gconstpointer</type></link>, <link linkend="guchar"><type>guchar</type></link>, <link linkend="guint"><type>guint</type></link>, <link linkend="gushort"><type>gushort</type></link>, <link linkend="gulong"><type>gulong</type></link>.
</para></listitem>
<listitem><para>
Types which correspond exactly to standard C types, but are included
for completeness - <link linkend="gchar"><type>gchar</type></link>, <link linkend="gint"><type>gint</type></link>, <link linkend="gshort"><type>gshort</type></link>, <link linkend="glong"><type>glong</type></link>, <link linkend="gfloat"><type>gfloat</type></link>, <link linkend="gdouble"><type>gdouble</type></link>,
<link linkend="gintptr"><type>gintptr</type></link>, <link linkend="guintptr"><type>guintptr</type></link>.
</para></listitem>
</itemizedlist>
</para>
</refsect1>

<refsect1 id="glib-Basic-Types.details" role="details">
<title role="details.title">Details</title>
<refsect2 id="gboolean" role="typedef">
<title>gboolean</title>
<indexterm zone="gboolean"><primary sortas="boolean">gboolean</primary></indexterm><programlisting>typedef gint   gboolean;
</programlisting>
<para>
A standard <type>boolean</type> type.
Variables of this type should only contain the value <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> or <link linkend="FALSE--CAPS"><literal>FALSE</literal></link>.
</para></refsect2>
<refsect2 id="gpointer" role="typedef">
<title>gpointer</title>
<indexterm zone="gpointer"><primary sortas="pointer">gpointer</primary></indexterm><programlisting>typedef void* gpointer;
</programlisting>
<para>
An untyped pointer.
<link linkend="gpointer"><type>gpointer</type></link> looks better and is easier to use than <type>void*</type>.
</para></refsect2>
<refsect2 id="gconstpointer" role="typedef">
<title>gconstpointer</title>
<indexterm zone="gconstpointer"><primary sortas="constpointer">gconstpointer</primary></indexterm><programlisting>typedef const void *gconstpointer;
</programlisting>
<para>
An untyped pointer to constant data.
The data pointed to should not be changed.
</para>
<para>
This is typically used in function prototypes to indicate that the
data pointed to will not be altered by the function.
</para></refsect2>
<refsect2 id="gchar" role="typedef">
<title>gchar</title>
<indexterm zone="gchar"><primary sortas="char">gchar</primary></indexterm><programlisting>typedef char   gchar;
</programlisting>
<para>
Corresponds to the standard C <type>char</type> type.
</para></refsect2>
<refsect2 id="guchar" role="typedef">
<title>guchar</title>
<indexterm zone="guchar"><primary sortas="uchar">guchar</primary></indexterm><programlisting>typedef unsigned char   guchar;
</programlisting>
<para>
Corresponds to the standard C <type>unsigned char</type> type.
</para></refsect2>
<refsect2 id="gint" role="typedef">
<title>gint</title>
<indexterm zone="gint"><primary sortas="int">gint</primary></indexterm><programlisting>typedef int    gint;
</programlisting>
<para>
Corresponds to the standard C <type>int</type> type.
Values of this type can range from <link linkend="G-MININT--CAPS"><type>G_MININT</type></link> to <link linkend="G-MAXINT--CAPS"><type>G_MAXINT</type></link>.
</para></refsect2>
<refsect2 id="guint" role="typedef">
<title>guint</title>
<indexterm zone="guint"><primary sortas="uint">guint</primary></indexterm><programlisting>typedef unsigned int    guint;
</programlisting>
<para>
Corresponds to the standard C <type>unsigned int</type> type.
Values of this type can range from 0 to <link linkend="G-MAXUINT--CAPS"><type>G_MAXUINT</type></link>.
</para></refsect2>
<refsect2 id="gshort" role="typedef">
<title>gshort</title>
<indexterm zone="gshort"><primary sortas="short">gshort</primary></indexterm><programlisting>typedef short  gshort;
</programlisting>
<para>
Corresponds to the standard C <type>short</type> type.
Values of this type can range from <link linkend="G-MINSHORT--CAPS"><type>G_MINSHORT</type></link> to <link linkend="G-MAXSHORT--CAPS"><type>G_MAXSHORT</type></link>.
</para></refsect2>
<refsect2 id="gushort" role="typedef">
<title>gushort</title>
<indexterm zone="gushort"><primary sortas="ushort">gushort</primary></indexterm><programlisting>typedef unsigned short  gushort;
</programlisting>
<para>
Corresponds to the standard C <type>unsigned short</type> type.
Values of this type can range from 0 to <link linkend="G-MAXUSHORT--CAPS"><type>G_MAXUSHORT</type></link>.
</para></refsect2>
<refsect2 id="glong" role="typedef">
<title>glong</title>
<indexterm zone="glong"><primary sortas="long">glong</primary></indexterm><programlisting>typedef long   glong;
</programlisting>
<para>
Corresponds to the standard C <type>long</type> type.
Values of this type can range from <link linkend="G-MINLONG--CAPS"><type>G_MINLONG</type></link> to <link linkend="G-MAXLONG--CAPS"><type>G_MAXLONG</type></link>.
</para></refsect2>
<refsect2 id="gulong" role="typedef">
<title>gulong</title>
<indexterm zone="gulong"><primary sortas="ulong">gulong</primary></indexterm><programlisting>typedef unsigned long   gulong;
</programlisting>
<para>
Corresponds to the standard C <type>unsigned long</type> type.
Values of this type can range from 0 to <link linkend="G-MAXULONG--CAPS"><type>G_MAXULONG</type></link>.
</para></refsect2>
<refsect2 id="gint8" role="typedef">
<title>gint8</title>
<indexterm zone="gint8"><primary sortas="int8">gint8</primary></indexterm><programlisting>typedef signed char gint8;
</programlisting>
<para>
A signed integer guaranteed to be 8 bits on all platforms.
Values of this type can range from -128 to 127.
</para></refsect2>
<refsect2 id="guint8" role="typedef">
<title>guint8</title>
<indexterm zone="guint8"><primary sortas="uint8">guint8</primary></indexterm><programlisting>typedef unsigned char guint8;
</programlisting>
<para>
An unsigned integer guaranteed to be 8 bits on all platforms.
Values of this type can range from 0 to 255.
</para></refsect2>
<refsect2 id="gint16" role="typedef">
<title>gint16</title>
<indexterm zone="gint16"><primary sortas="int16">gint16</primary></indexterm><programlisting>typedef signed short gint16;
</programlisting>
<para>
A signed integer guaranteed to be 16 bits on all platforms.
Values of this type can range from -32,768 to 32,767.
</para>
<para>
To print or scan values of this type, use
<link linkend="G-GINT16-MODIFIER--CAPS"><literal>G_GINT16_MODIFIER</literal></link> and/or <link linkend="G-GINT16-FORMAT--CAPS"><literal>G_GINT16_FORMAT</literal></link>.
</para></refsect2>
<refsect2 id="guint16" role="typedef">
<title>guint16</title>
<indexterm zone="guint16"><primary sortas="uint16">guint16</primary></indexterm><programlisting>typedef unsigned short guint16;
</programlisting>
<para>
An unsigned integer guaranteed to be 16 bits on all platforms.
Values of this type can range from 0 to 65,535.
</para>
<para>
To print or scan values of this type, use
<link linkend="G-GINT16-MODIFIER--CAPS"><literal>G_GINT16_MODIFIER</literal></link> and/or <link linkend="G-GUINT16-FORMAT--CAPS"><literal>G_GUINT16_FORMAT</literal></link>.
</para></refsect2>
<refsect2 id="gint32" role="typedef">
<title>gint32</title>
<indexterm zone="gint32"><primary sortas="int32">gint32</primary></indexterm><programlisting>typedef signed int gint32;
</programlisting>
<para>
A signed integer guaranteed to be 32 bits on all platforms.
Values of this type can range from -2,147,483,648 to 2,147,483,647.
</para>
<para>
To print or scan values of this type, use
<link linkend="G-GINT32-MODIFIER--CAPS"><literal>G_GINT32_MODIFIER</literal></link> and/or <link linkend="G-GINT32-FORMAT--CAPS"><literal>G_GINT32_FORMAT</literal></link>.
</para></refsect2>
<refsect2 id="guint32" role="typedef">
<title>guint32</title>
<indexterm zone="guint32"><primary sortas="uint32">guint32</primary></indexterm><programlisting>typedef unsigned int guint32;
</programlisting>
<para>
An unsigned integer guaranteed to be 32 bits on all platforms.
Values of this type can range from 0 to 4,294,967,295.
</para>
<para>
To print or scan values of this type, use
<link linkend="G-GINT32-MODIFIER--CAPS"><literal>G_GINT32_MODIFIER</literal></link> and/or <link linkend="G-GUINT32-FORMAT--CAPS"><literal>G_GUINT32_FORMAT</literal></link>.
</para></refsect2>
<refsect2 id="G-HAVE-GINT64--CAPS" role="macro" condition="deprecated">
<title>G_HAVE_GINT64</title>
<indexterm zone="G-HAVE-GINT64--CAPS" role="deprecated"><primary sortas="HAVE_GINT64">G_HAVE_GINT64</primary></indexterm><programlisting>#define G_HAVE_GINT64 1          /* deprecated, always true */
</programlisting>
<warning><para><literal>G_HAVE_GINT64</literal> is deprecated and should not be used in newly-written code. GLib requires 64-bit integer support since version 2.0, therefore
<link linkend="G-HAVE-GINT64--CAPS"><literal>G_HAVE_GINT64</literal></link> is <emphasis>always</emphasis> defined.</para></warning>
<para>
This macro is defined if 64-bit signed and unsigned integers are available
on the platform.
</para></refsect2>
<refsect2 id="gint64" role="typedef">
<title>gint64</title>
<indexterm zone="gint64"><primary sortas="int64">gint64</primary></indexterm><programlisting>typedef signed long gint64;
</programlisting>
<para>
A signed integer guaranteed to be 64 bits on all platforms.
Values of this type can range from -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807.
</para>
<para>
To print or scan values of this type, use
<link linkend="G-GINT64-MODIFIER--CAPS"><literal>G_GINT64_MODIFIER</literal></link> and/or <link linkend="G-GINT64-FORMAT--CAPS"><literal>G_GINT64_FORMAT</literal></link>.
</para></refsect2>
<refsect2 id="guint64" role="typedef">
<title>guint64</title>
<indexterm zone="guint64"><primary sortas="uint64">guint64</primary></indexterm><programlisting>typedef unsigned long guint64;
</programlisting>
<para>
An unsigned integer guaranteed to be 64 bits on all platforms.
Values of this type can range from 0 to 18,446,744,073,709,551,615.
</para>
<para>
To print or scan values of this type, use
<link linkend="G-GINT64-MODIFIER--CAPS"><literal>G_GINT64_MODIFIER</literal></link> and/or <link linkend="G-GUINT64-FORMAT--CAPS"><literal>G_GUINT64_FORMAT</literal></link>.
</para></refsect2>
<refsect2 id="G-GINT64-CONSTANT--CAPS" role="macro">
<title>G_GINT64_CONSTANT()</title>
<indexterm zone="G-GINT64-CONSTANT--CAPS"><primary sortas="GINT64_CONSTANT">G_GINT64_CONSTANT</primary></indexterm><programlisting>#define G_GINT64_CONSTANT(val)	(val##L)
</programlisting>
<para>
This macro is used to insert 64-bit integer literals into the source code.
</para><variablelist role="params">
<varlistentry><term><parameter>val</parameter>&#160;:</term>
<listitem><simpara>a literal integer value, e.g. 0x1d636b02300a7aa7.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="G-GUINT64-CONSTANT--CAPS" role="macro" condition="since:2.10">
<title>G_GUINT64_CONSTANT()</title>
<indexterm zone="G-GUINT64-CONSTANT--CAPS" role="2.10"><primary sortas="GUINT64_CONSTANT">G_GUINT64_CONSTANT</primary></indexterm><programlisting>#define G_GUINT64_CONSTANT(val)	(val##UL)
</programlisting>
<para>
This macro is used to insert 64-bit unsigned integer literals into the
source code.
</para><variablelist role="params">
<varlistentry><term><parameter>val</parameter>&#160;:</term>
<listitem><simpara>a literal integer value, e.g. 0x1d636b02300a7aa7U.
</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 2.10</para></refsect2>
<refsect2 id="gfloat" role="typedef">
<title>gfloat</title>
<indexterm zone="gfloat"><primary sortas="float">gfloat</primary></indexterm><programlisting>typedef float   gfloat;
</programlisting>
<para>
Corresponds to the standard C <type>float</type> type.
Values of this type can range from -<link linkend="G-MAXFLOAT--CAPS"><type>G_MAXFLOAT</type></link> to <link linkend="G-MAXFLOAT--CAPS"><type>G_MAXFLOAT</type></link>.
</para></refsect2>
<refsect2 id="gdouble" role="typedef">
<title>gdouble</title>
<indexterm zone="gdouble"><primary sortas="double">gdouble</primary></indexterm><programlisting>typedef double  gdouble;
</programlisting>
<para>
Corresponds to the standard C <type>double</type> type.
Values of this type can range from -<link linkend="G-MAXDOUBLE--CAPS"><type>G_MAXDOUBLE</type></link> to <link linkend="G-MAXDOUBLE--CAPS"><type>G_MAXDOUBLE</type></link>.
</para></refsect2>
<refsect2 id="gsize" role="typedef">
<title>gsize</title>
<indexterm zone="gsize"><primary sortas="size">gsize</primary></indexterm><programlisting>typedef unsigned long gsize;
</programlisting>
<para>
An unsigned integer type of the result of the sizeof operator, corresponding
to the size_t type defined in C99. This type is wide enough to hold the numeric
value of a pointer, so it is usually 32bit wide on a 32bit platform and
64bit wide on a 64bit platform.
</para>
<para>
To print or scan values of this type, use
<link linkend="G-GSIZE-MODIFIER--CAPS"><literal>G_GSIZE_MODIFIER</literal></link> and/or <link linkend="G-GSIZE-FORMAT--CAPS"><literal>G_GSIZE_FORMAT</literal></link>.
</para></refsect2>
<refsect2 id="gssize" role="typedef">
<title>gssize</title>
<indexterm zone="gssize"><primary sortas="ssize">gssize</primary></indexterm><programlisting>typedef signed long gssize;
</programlisting>
<para>
A signed variant of gsize, corresponding to the ssize_t defined on most platforms.
</para>
<para>
To print or scan values of this type, use
<link linkend="G-GSIZE-MODIFIER--CAPS"><literal>G_GSIZE_MODIFIER</literal></link> and/or <link linkend="G-GSSIZE-FORMAT--CAPS"><literal>G_GSSIZE_FORMAT</literal></link>.
</para></refsect2>
<refsect2 id="goffset" role="typedef">
<title>goffset</title>
<indexterm zone="goffset"><primary sortas="offset">goffset</primary></indexterm><programlisting>typedef gint64 goffset;
</programlisting>
<para>
A signed integer type that is used for file offsets, corresponding to the
C99 type off64_t.
</para>
<para>
To print or scan values of this type, use
<link linkend="G-GOFFSET-MODIFIER--CAPS"><literal>G_GOFFSET_MODIFIER</literal></link> and/or <link linkend="G-GOFFSET-FORMAT--CAPS"><literal>G_GOFFSET_FORMAT</literal></link>.
</para>
Since: 2.14</refsect2>
<refsect2 id="G-GOFFSET-CONSTANT--CAPS" role="macro">
<title>G_GOFFSET_CONSTANT()</title>
<indexterm zone="G-GOFFSET-CONSTANT--CAPS"><primary sortas="GOFFSET_CONSTANT">G_GOFFSET_CONSTANT</primary></indexterm><programlisting>#define G_GOFFSET_CONSTANT(val) G_GINT64_CONSTANT(val)
</programlisting>
<para>
This macro is used to insert <link linkend="goffset"><type>goffset</type></link> 64-bit integer literals into the source code.
See also <link linkend="G-GINT64-CONSTANT--CAPS"><type>G_GINT64_CONSTANT</type></link>.
</para><variablelist role="params">
<varlistentry><term><parameter>val</parameter>&#160;:</term>
<listitem><simpara>a literal integer value, e.g. 0x1d636b02300a7aa7.
Since: 2.20
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="gintptr" role="typedef">
<title>gintptr</title>
<indexterm zone="gintptr"><primary sortas="intptr">gintptr</primary></indexterm><programlisting>typedef signed long gintptr;
</programlisting>
<para>
Corresponds to the C99 type <type>intptr_t</type>, a signed integer type that
can hold any pointer.
</para>
<para>
To print or scan values of this type, use
<link linkend="G-GINTPTR-MODIFIER--CAPS"><literal>G_GINTPTR_MODIFIER</literal></link> and/or <link linkend="G-GINTPTR-FORMAT--CAPS"><literal>G_GINTPTR_FORMAT</literal></link>.
</para>
Since: 2.18</refsect2>
<refsect2 id="guintptr" role="typedef">
<title>guintptr</title>
<indexterm zone="guintptr"><primary sortas="uintptr">guintptr</primary></indexterm><programlisting>typedef unsigned long guintptr;
</programlisting>
<para>
Corresponds to the C99 type <type>uintptr_t</type>, an unsigned integer type that
can hold any pointer.
</para>
<para>
To print or scan values of this type, use
<link linkend="G-GINTPTR-MODIFIER--CAPS"><literal>G_GINTPTR_MODIFIER</literal></link> and/or <link linkend="G-GUINTPTR-FORMAT--CAPS"><literal>G_GUINTPTR_FORMAT</literal></link>.
</para>
Since: 2.18</refsect2>

</refsect1>




</refentry>
