<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN'
                      'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [
<!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
<!ENTITY version SYSTEM "version.xml">
]>
<refentry id="glib-Miscellaneous-Macros">
<refmeta>
<refentrytitle role="top_of_page" id="glib-Miscellaneous-Macros.top_of_page">Miscellaneous Macros</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GLIB Library</refmiscinfo>
</refmeta>
<refnamediv>
<refname>Miscellaneous Macros</refname>
<refpurpose>specialized macros which are not used often</refpurpose>
</refnamediv>

<refsect1 id="glib-Miscellaneous-Macros.functions" role="functions_proto">
<title role="functions_proto.title">Functions</title>
<informaltable pgwide="1" frame="none">
<tgroup cols="2">
<colspec colname="functions_proto_type" colwidth="150px"/>
<colspec colname="functions_proto_name"/>
<tbody>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="g-auto">g_auto</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="g-autoptr">g_autoptr</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="g-autolist">g_autolist</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="g-autoslist">g_autoslist</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="g-autoqueue">g_autoqueue</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-DEFINE-AUTOPTR-CLEANUP-FUNC:CAPS">G_DEFINE_AUTOPTR_CLEANUP_FUNC</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-DEFINE-AUTO-CLEANUP-CLEAR-FUNC:CAPS">G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-DEFINE-AUTO-CLEANUP-FREE-FUNC:CAPS">G_DEFINE_AUTO_CLEANUP_FREE_FUNC</link><phrase role="c_punctuation">()</phrase></entry></row>



<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-VA-COPY:CAPS">G_VA_COPY</link><phrase role="c_punctuation">()</phrase></entry></row>

<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-STRINGIFY:CAPS">G_STRINGIFY</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-PASTE:CAPS">G_PASTE</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-STATIC-ASSERT:CAPS">G_STATIC_ASSERT</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-STATIC-ASSERT-EXPR:CAPS">G_STATIC_ASSERT_EXPR</link><phrase role="c_punctuation">()</phrase></entry></row>

<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-CHECK-VERSION:CAPS">G_GNUC_CHECK_VERSION</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-ALLOC-SIZE:CAPS">G_GNUC_ALLOC_SIZE</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-ALLOC-SIZE2:CAPS">G_GNUC_ALLOC_SIZE2</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-DEPRECATED-FOR:CAPS">G_GNUC_DEPRECATED_FOR</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-PRINTF:CAPS">G_GNUC_PRINTF</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-SCANF:CAPS">G_GNUC_SCANF</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-STRFTIME:CAPS">G_GNUC_STRFTIME</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-FORMAT:CAPS">G_GNUC_FORMAT</link><phrase role="c_punctuation">()</phrase></entry></row>

<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-DEPRECATED-FOR:CAPS">G_DEPRECATED_FOR</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-UNAVAILABLE:CAPS">G_UNAVAILABLE</link><phrase role="c_punctuation">()</phrase></entry></row>

<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-LIKELY:CAPS">G_LIKELY</link><phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-UNLIKELY:CAPS">G_UNLIKELY</link><phrase role="c_punctuation">()</phrase></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 id="glib-Miscellaneous-Macros.other" role="other_proto">
<title role="other_proto.title">Types and Values</title>
<informaltable pgwide="1" frame="none">
<tgroup cols="2">
<colspec colname="other_proto_type" colwidth="150px"/>
<colspec colname="other_proto_name"/>
<tbody>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-INLINE-FUNC:CAPS">G_INLINE_FUNC</link></entry></row>

<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="g-autofree">g_autofree</link></entry></row>

<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-STMT-START:CAPS">G_STMT_START</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-STMT-END:CAPS">G_STMT_END</link></entry></row>

<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-BEGIN-DECLS:CAPS">G_BEGIN_DECLS</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-END-DECLS:CAPS">G_END_DECLS</link></entry></row>



<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-EXTENSION:CAPS">G_GNUC_EXTENSION</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-CONST:CAPS">G_GNUC_CONST</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-PURE:CAPS">G_GNUC_PURE</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-MALLOC:CAPS">G_GNUC_MALLOC</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-DEPRECATED:CAPS">G_GNUC_DEPRECATED</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-BEGIN-IGNORE-DEPRECATIONS:CAPS">G_GNUC_BEGIN_IGNORE_DEPRECATIONS</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-END-IGNORE-DEPRECATIONS:CAPS">G_GNUC_END_IGNORE_DEPRECATIONS</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-NORETURN:CAPS">G_GNUC_NORETURN</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-FALLTHROUGH:CAPS">G_GNUC_FALLTHROUGH</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-UNUSED:CAPS">G_GNUC_UNUSED</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-NULL-TERMINATED:CAPS">G_GNUC_NULL_TERMINATED</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-WARN-UNUSED-RESULT:CAPS">G_GNUC_WARN_UNUSED_RESULT</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-FUNCTION:CAPS">G_GNUC_FUNCTION</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-PRETTY-FUNCTION:CAPS">G_GNUC_PRETTY_FUNCTION</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-NO-INLINE:CAPS">G_GNUC_NO_INLINE</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-NO-INSTRUMENT:CAPS">G_GNUC_NO_INSTRUMENT</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-HAVE-GNUC-VISIBILITY:CAPS">G_HAVE_GNUC_VISIBILITY</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-INTERNAL:CAPS">G_GNUC_INTERNAL</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-GNUC-MAY-ALIAS:CAPS">G_GNUC_MAY_ALIAS</link></entry></row>

<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-DEPRECATED:CAPS">G_DEPRECATED</link></entry></row>


<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-STRLOC:CAPS">G_STRLOC</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-STRFUNC:CAPS">G_STRFUNC</link></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>

<refsect1 id="glib-Miscellaneous-Macros.includes"><title>Includes</title><synopsis>#include &lt;glib.h&gt;
</synopsis></refsect1>

<refsect1 id="glib-Miscellaneous-Macros.description" role="desc">
<title role="desc.title">Description</title>
<para>These macros provide more specialized features which are not
needed so often by application programmers.</para>

</refsect1>
<refsect1 id="glib-Miscellaneous-Macros.functions_details" role="details">
<title role="details.title">Functions</title>
<refsect2 id="g-auto" role="macro" condition="since:2.44">
<title>g_auto()</title>
<indexterm zone="g-auto" role="2.44"><primary sortas="auto">g_auto</primary></indexterm>
<programlisting language="C">#define             g_auto(TypeName)</programlisting>
<para>Helper to declare a variable with automatic cleanup.</para>
<para>The variable is cleaned up in a way appropriate to its type when the
variable goes out of scope.  The type must support this.
The way to clean up the type must have been defined using one of the macros
<link linkend="G-DEFINE-AUTO-CLEANUP-CLEAR-FUNC:CAPS"><function>G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC()</function></link> or <link linkend="G-DEFINE-AUTO-CLEANUP-FREE-FUNC:CAPS"><function>G_DEFINE_AUTO_CLEANUP_FREE_FUNC()</function></link>.</para>
<para>This feature is only supported on GCC and clang.  This macro is not
defined on other compilers and should not be used in programs that
are intended to be portable to those compilers.</para>
<para>This is meant to be used with stack-allocated structures and
non-pointer types.  For the (more commonly used) pointer version, see
<link linkend="g-autoptr"><function>g_autoptr()</function></link>.</para>
<para>This macro can be used to avoid having to do explicit cleanups of
local variables when exiting functions.  It often vastly simplifies
handling of error conditions, removing the need for various tricks
such as <literal>goto out</literal> or repeating of cleanup code.  It is also helpful
for non-error cases.</para>
<para>Consider the following example:</para>
<informalexample><programlisting role="example"><![CDATA[
GVariant *
my_func(void)
{
  g_auto(GQueue) queue = G_QUEUE_INIT;
  g_auto(GVariantBuilder) builder;
  g_auto(GStrv) strv;

  g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
  strv = g_strsplit("a:b:c", ":", -1);

  ...

  if (error_condition)
    return NULL;

  ...

  return g_variant_builder_end (&builder);
}
]]></programlisting></informalexample>
<para></para>
<para>You must initialize the variable in some way — either by use of an
initialiser or by ensuring that an <literal>_init</literal> function will be called on
it unconditionally before it goes out of scope.</para>
<refsect3 id="g-auto.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>TypeName</para></entry>
<entry role="parameter_description"><para>a supported variable type</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.44">2.44</link></para></refsect2>
<refsect2 id="g-autoptr" role="macro" condition="since:2.44">
<title>g_autoptr()</title>
<indexterm zone="g-autoptr" role="2.44"><primary sortas="autoptr">g_autoptr</primary></indexterm>
<programlisting language="C">#define             g_autoptr(TypeName)</programlisting>
<para>Helper to declare a pointer variable with automatic cleanup.</para>
<para>The variable is cleaned up in a way appropriate to its type when the
variable goes out of scope.  The type must support this.
The way to clean up the type must have been defined using the macro
<link linkend="G-DEFINE-AUTOPTR-CLEANUP-FUNC:CAPS"><function>G_DEFINE_AUTOPTR_CLEANUP_FUNC()</function></link>.</para>
<para>This feature is only supported on GCC and clang.  This macro is not
defined on other compilers and should not be used in programs that
are intended to be portable to those compilers.</para>
<para>This is meant to be used to declare pointers to types with cleanup
functions.  The type of the variable is a pointer to <parameter>TypeName</parameter>
.  You
must not add your own <literal>*</literal>.</para>
<para>This macro can be used to avoid having to do explicit cleanups of
local variables when exiting functions.  It often vastly simplifies
handling of error conditions, removing the need for various tricks
such as <literal>goto out</literal> or repeating of cleanup code.  It is also helpful
for non-error cases.</para>
<para>Consider the following example:</para>
<informalexample><programlisting role="example"><![CDATA[
gboolean
check_exists(GVariant *dict)
{
  g_autoptr(GVariant) dirname, basename = NULL;
  g_autofree gchar *path = NULL;

  dirname = g_variant_lookup_value (dict, "dirname", G_VARIANT_TYPE_STRING);

  if (dirname == NULL)
    return FALSE;

  basename = g_variant_lookup_value (dict, "basename", G_VARIANT_TYPE_STRING);

  if (basename == NULL)
    return FALSE;

  path = g_build_filename (g_variant_get_string (dirname, NULL),
                           g_variant_get_string (basename, NULL),
                           NULL);

  return g_access (path, R_OK) == 0;
}
]]></programlisting></informalexample>
<para></para>
<para>You must initialise the variable in some way — either by use of an
initialiser or by ensuring that it is assigned to unconditionally
before it goes out of scope.</para>
<para>See also <link linkend="g-auto"><function>g_auto()</function></link>, <link linkend="g-autofree"><function>g_autofree()</function></link> and <link linkend="g-steal-pointer"><function>g_steal_pointer()</function></link>.</para>
<refsect3 id="g-autoptr.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>TypeName</para></entry>
<entry role="parameter_description"><para>a supported variable type</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.44">2.44</link></para></refsect2>
<refsect2 id="g-autolist" role="macro" condition="since:2.56">
<title>g_autolist()</title>
<indexterm zone="g-autolist" role="2.56"><primary sortas="autolist">g_autolist</primary></indexterm>
<programlisting language="C">#define             g_autolist(TypeName)</programlisting>
<para>Helper to declare a list variable with automatic deep cleanup.</para>
<para>The list is deeply freed, in a way appropriate to the specified type, when the
variable goes out of scope.  The type must support this.</para>
<para>This feature is only supported on GCC and clang.  This macro is not
defined on other compilers and should not be used in programs that
are intended to be portable to those compilers.</para>
<para>This is meant to be used to declare lists of a type with a cleanup
function.  The type of the variable is a <literal>GList *</literal>.  You
must not add your own <literal>*</literal>.</para>
<para>This macro can be used to avoid having to do explicit cleanups of
local variables when exiting functions.  It often vastly simplifies
handling of error conditions, removing the need for various tricks
such as <literal>goto out</literal> or repeating of cleanup code.  It is also helpful
for non-error cases.</para>
<para>See also <link linkend="g-autoslist"><function>g_autoslist()</function></link>, <link linkend="g-autoptr"><function>g_autoptr()</function></link> and <link linkend="g-steal-pointer"><function>g_steal_pointer()</function></link>.</para>
<refsect3 id="g-autolist.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>TypeName</para></entry>
<entry role="parameter_description"><para>a supported variable type</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.56">2.56</link></para></refsect2>
<refsect2 id="g-autoslist" role="macro" condition="since:2.56">
<title>g_autoslist()</title>
<indexterm zone="g-autoslist" role="2.56"><primary sortas="autoslist">g_autoslist</primary></indexterm>
<programlisting language="C">#define             g_autoslist(TypeName)</programlisting>
<para>Helper to declare a singly linked list variable with automatic deep cleanup.</para>
<para>The list is deeply freed, in a way appropriate to the specified type, when the
variable goes out of scope.  The type must support this.</para>
<para>This feature is only supported on GCC and clang.  This macro is not
defined on other compilers and should not be used in programs that
are intended to be portable to those compilers.</para>
<para>This is meant to be used to declare lists of a type with a cleanup
function.  The type of the variable is a <literal>GSList *</literal>.  You
must not add your own <literal>*</literal>.</para>
<para>This macro can be used to avoid having to do explicit cleanups of
local variables when exiting functions.  It often vastly simplifies
handling of error conditions, removing the need for various tricks
such as <literal>goto out</literal> or repeating of cleanup code.  It is also helpful
for non-error cases.</para>
<para>See also <link linkend="g-autolist"><function>g_autolist()</function></link>, <link linkend="g-autoptr"><function>g_autoptr()</function></link> and <link linkend="g-steal-pointer"><function>g_steal_pointer()</function></link>.</para>
<refsect3 id="g-autoslist.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>TypeName</para></entry>
<entry role="parameter_description"><para>a supported variable type</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.56">2.56</link></para></refsect2>
<refsect2 id="g-autoqueue" role="macro" condition="since:2.62">
<title>g_autoqueue()</title>
<indexterm zone="g-autoqueue" role="2.62"><primary sortas="autoqueue">g_autoqueue</primary></indexterm>
<programlisting language="C">#define             g_autoqueue(TypeName)</programlisting>
<para>Helper to declare a double-ended queue variable with automatic deep cleanup.</para>
<para>The queue is deeply freed, in a way appropriate to the specified type, when the
variable goes out of scope.  The type must support this.</para>
<para>This feature is only supported on GCC and clang.  This macro is not
defined on other compilers and should not be used in programs that
are intended to be portable to those compilers.</para>
<para>This is meant to be used to declare queues of a type with a cleanup
function.  The type of the variable is a <literal>GQueue *</literal>.  You
must not add your own <literal>*</literal>.</para>
<para>This macro can be used to avoid having to do explicit cleanups of
local variables when exiting functions.  It often vastly simplifies
handling of error conditions, removing the need for various tricks
such as <literal>goto out</literal> or repeating of cleanup code.  It is also helpful
for non-error cases.</para>
<para>See also <link linkend="g-autolist"><function>g_autolist()</function></link>, <link linkend="g-autoptr"><function>g_autoptr()</function></link> and <link linkend="g-steal-pointer"><function>g_steal_pointer()</function></link>.</para>
<refsect3 id="g-autoqueue.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>TypeName</para></entry>
<entry role="parameter_description"><para>a supported variable type</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.62">2.62</link></para></refsect2>
<refsect2 id="G-DEFINE-AUTOPTR-CLEANUP-FUNC:CAPS" role="macro" condition="since:2.44">
<title>G_DEFINE_AUTOPTR_CLEANUP_FUNC()</title>
<indexterm zone="G-DEFINE-AUTOPTR-CLEANUP-FUNC:CAPS" role="2.44"><primary sortas="DEFINE_AUTOPTR_CLEANUP_FUNC">G_DEFINE_AUTOPTR_CLEANUP_FUNC</primary></indexterm>
<programlisting language="C">#define             G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func)</programlisting>
<para>Defines the appropriate cleanup function for a pointer type.</para>
<para>The function will not be called if the variable to be cleaned up
contains <link linkend="NULL:CAPS"><literal>NULL</literal></link>.</para>
<para>This will typically be the <literal><link linkend="free"><function>_free()</function></link></literal> or <literal><link linkend="unref"><function>_unref()</function></link></literal> function for the given
type.</para>
<para>With this definition, it will be possible to use <link linkend="g-autoptr"><function>g_autoptr()</function></link> with
<parameter>TypeName</parameter>
.</para>
<informalexample><programlisting role="example"><![CDATA[
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GObject, g_object_unref)
]]></programlisting></informalexample>
<para></para>
<para>This macro should be used unconditionally; it is a no-op on compilers
where cleanup is not supported.</para>
<refsect3 id="G-DEFINE-AUTOPTR-CLEANUP-FUNC.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>TypeName</para></entry>
<entry role="parameter_description"><para>a type name to define a <link linkend="g-autoptr"><function>g_autoptr()</function></link> cleanup function for</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>func</para></entry>
<entry role="parameter_description"><para>the cleanup function</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.44">2.44</link></para></refsect2>
<refsect2 id="G-DEFINE-AUTO-CLEANUP-CLEAR-FUNC:CAPS" role="macro" condition="since:2.44">
<title>G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC()</title>
<indexterm zone="G-DEFINE-AUTO-CLEANUP-CLEAR-FUNC:CAPS" role="2.44"><primary sortas="DEFINE_AUTO_CLEANUP_CLEAR_FUNC">G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC</primary></indexterm>
<programlisting language="C">#define             G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func)</programlisting>
<para>Defines the appropriate cleanup function for a type.</para>
<para>This will typically be the <literal><link linkend="clear"><function>_clear()</function></link></literal> function for the given type.</para>
<para>With this definition, it will be possible to use <link linkend="g-auto"><function>g_auto()</function></link> with
<parameter>TypeName</parameter>
.</para>
<informalexample><programlisting role="example"><![CDATA[
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GQueue, g_queue_clear)
]]></programlisting></informalexample>
<para></para>
<para>This macro should be used unconditionally; it is a no-op on compilers
where cleanup is not supported.</para>
<refsect3 id="G-DEFINE-AUTO-CLEANUP-CLEAR-FUNC.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>TypeName</para></entry>
<entry role="parameter_description"><para>a type name to define a <link linkend="g-auto"><function>g_auto()</function></link> cleanup function for</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>func</para></entry>
<entry role="parameter_description"><para>the clear function</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.44">2.44</link></para></refsect2>
<refsect2 id="G-DEFINE-AUTO-CLEANUP-FREE-FUNC:CAPS" role="macro" condition="since:2.44">
<title>G_DEFINE_AUTO_CLEANUP_FREE_FUNC()</title>
<indexterm zone="G-DEFINE-AUTO-CLEANUP-FREE-FUNC:CAPS" role="2.44"><primary sortas="DEFINE_AUTO_CLEANUP_FREE_FUNC">G_DEFINE_AUTO_CLEANUP_FREE_FUNC</primary></indexterm>
<programlisting language="C">#define             G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none)</programlisting>
<para>Defines the appropriate cleanup function for a type.</para>
<para>With this definition, it will be possible to use <link linkend="g-auto"><function>g_auto()</function></link> with
<parameter>TypeName</parameter>
.</para>
<para>This function will be rarely used.  It is used with pointer-based
typedefs and non-pointer types where the value of the variable
represents a resource that must be freed.  Two examples are <link linkend="GStrv"><type>GStrv</type></link>
and file descriptors.</para>
<para><parameter>none</parameter>
 specifies the "none" value for the type in question.  It is
probably something like <link linkend="NULL:CAPS"><literal>NULL</literal></link> or <literal>-1</literal>.  If the variable is found to
contain this value then the free function will not be called.</para>
<informalexample><programlisting role="example"><![CDATA[
G_DEFINE_AUTO_CLEANUP_FREE_FUNC(GStrv, g_strfreev, NULL)
]]></programlisting></informalexample>
<para></para>
<para>This macro should be used unconditionally; it is a no-op on compilers
where cleanup is not supported.</para>
<refsect3 id="G-DEFINE-AUTO-CLEANUP-FREE-FUNC.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>TypeName</para></entry>
<entry role="parameter_description"><para>a type name to define a <link linkend="g-auto"><function>g_auto()</function></link> cleanup function for</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>func</para></entry>
<entry role="parameter_description"><para>the free function</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>none</para></entry>
<entry role="parameter_description"><para>the "none" value for the type</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.44">2.44</link></para></refsect2>
<refsect2 id="G-VA-COPY:CAPS" role="macro">
<title>G_VA_COPY()</title>
<indexterm zone="G-VA-COPY:CAPS"><primary sortas="VA_COPY">G_VA_COPY</primary></indexterm>
<programlisting language="C">#define             G_VA_COPY(ap1,ap2)</programlisting>
<para>Portable way to copy va_list variables.</para>
<para>In order to use this function, you must include string.h yourself,
because this macro may use <link linkend="memmove"><function>memmove()</function></link> and GLib does not include
string.h for you.</para>
<refsect3 id="G-VA-COPY.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>ap1</para></entry>
<entry role="parameter_description"><para>the va_list variable to place a copy of <parameter>ap2</parameter>
in</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>ap2</para></entry>
<entry role="parameter_description"><para>a va_list</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="G-STRINGIFY:CAPS" role="macro">
<title>G_STRINGIFY()</title>
<indexterm zone="G-STRINGIFY:CAPS"><primary sortas="STRINGIFY">G_STRINGIFY</primary></indexterm>
<programlisting language="C">#define G_STRINGIFY(macro_or_string)&#160;G_STRINGIFY_ARG (macro_or_string)
</programlisting>
<para>Accepts a macro or a string and converts it into a string after
preprocessor argument expansion. For example, the following code:</para>
<informalexample><programlisting role="example"><![CDATA[
#define AGE 27
const gchar *greeting = G_STRINGIFY (AGE) " today!";
]]></programlisting></informalexample>
<para></para>
<para>is transformed by the preprocessor into (code equivalent to):</para>
<informalexample><programlisting role="example"><![CDATA[
const gchar *greeting = "27 today!";
]]></programlisting></informalexample>
<para></para>
<refsect3 id="G-STRINGIFY.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>macro_or_string</para></entry>
<entry role="parameter_description"><para>a macro or a string</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="G-PASTE:CAPS" role="macro" condition="since:2.20">
<title>G_PASTE()</title>
<indexterm zone="G-PASTE:CAPS" role="2.20"><primary sortas="PASTE">G_PASTE</primary></indexterm>
<programlisting language="C">#define G_PASTE(identifier1,identifier2)      G_PASTE_ARGS (identifier1, identifier2)
</programlisting>
<para>Yields a new preprocessor pasted identifier
<parameter>identifier1identifier2</parameter>
 from its expanded
arguments <parameter>identifier1</parameter>
 and <parameter>identifier2</parameter>
. For example,
the following code:</para>
<informalexample><programlisting role="example"><![CDATA[
#define GET(traveller,method) G_PASTE(traveller_get_, method) (traveller)
const gchar *name = GET (traveller, name);
const gchar *quest = GET (traveller, quest);
GdkColor *favourite = GET (traveller, favourite_colour);
]]></programlisting></informalexample>
<para></para>
<para>is transformed by the preprocessor into:</para>
<informalexample><programlisting role="example"><![CDATA[
const gchar *name = traveller_get_name (traveller);
const gchar *quest = traveller_get_quest (traveller);
GdkColor *favourite = traveller_get_favourite_colour (traveller);
]]></programlisting></informalexample>
<para></para>
<refsect3 id="G-PASTE.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>identifier1</para></entry>
<entry role="parameter_description"><para>an identifier</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>identifier2</para></entry>
<entry role="parameter_description"><para>an identifier</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.20">2.20</link></para></refsect2>
<refsect2 id="G-STATIC-ASSERT:CAPS" role="macro" condition="since:2.20">
<title>G_STATIC_ASSERT()</title>
<indexterm zone="G-STATIC-ASSERT:CAPS" role="2.20"><primary sortas="STATIC_ASSERT">G_STATIC_ASSERT</primary></indexterm>
<programlisting language="C">#define G_STATIC_ASSERT(expr) _Static_assert (expr, "Expression evaluates to false")
</programlisting>
<para>The <link linkend="G-STATIC-ASSERT:CAPS"><function>G_STATIC_ASSERT()</function></link> macro lets the programmer check
a condition at compile time, the condition needs to
be compile time computable. The macro can be used in
any place where a typedef is valid.</para>
<para>A typedef is generally allowed in exactly the same places that
a variable declaration is allowed. For this reason, you should
not use <link linkend="G-STATIC-ASSERT:CAPS"><function>G_STATIC_ASSERT()</function></link> in the middle of blocks of code.</para>
<para>The macro should only be used once per source code line.</para>
<refsect3 id="G-STATIC-ASSERT.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>expr</para></entry>
<entry role="parameter_description"><para>a constant expression</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.20">2.20</link></para></refsect2>
<refsect2 id="G-STATIC-ASSERT-EXPR:CAPS" role="macro" condition="since:2.30">
<title>G_STATIC_ASSERT_EXPR()</title>
<indexterm zone="G-STATIC-ASSERT-EXPR:CAPS" role="2.30"><primary sortas="STATIC_ASSERT_EXPR">G_STATIC_ASSERT_EXPR</primary></indexterm>
<programlisting language="C">#define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1 : -1]))
</programlisting>
<para>The <link linkend="G-STATIC-ASSERT-EXPR:CAPS"><function>G_STATIC_ASSERT_EXPR()</function></link> macro lets the programmer check
a condition at compile time. The condition needs to be
compile time computable.</para>
<para>Unlike <link linkend="G-STATIC-ASSERT:CAPS"><function>G_STATIC_ASSERT()</function></link>, this macro evaluates to an expression
and, as such, can be used in the middle of other expressions.
Its value should be ignored. This can be accomplished by placing
it as the first argument of a comma expression.</para>
<informalexample><programlisting role="example"><![CDATA[
#define ADD_ONE_TO_INT(x) \
  (G_STATIC_ASSERT_EXPR(sizeof (x) == sizeof (int)), ((x) + 1))
]]></programlisting></informalexample>
<para></para>
<refsect3 id="G-STATIC-ASSERT-EXPR.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>expr</para></entry>
<entry role="parameter_description"><para>a constant expression</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.30">2.30</link></para></refsect2>
<refsect2 id="G-GNUC-CHECK-VERSION:CAPS" role="macro" condition="since:2.42">
<title>G_GNUC_CHECK_VERSION()</title>
<indexterm zone="G-GNUC-CHECK-VERSION:CAPS" role="2.42"><primary sortas="GNUC_CHECK_VERSION">G_GNUC_CHECK_VERSION</primary></indexterm>
<programlisting language="C">#define             G_GNUC_CHECK_VERSION(major, minor)</programlisting>
<para>Expands to a check for a compiler with __GNUC__ defined and a version
greater than or equal to the major and minor numbers provided. For example,
the following would only match on compilers such as GCC 4.8 or newer.</para>
<informalexample><programlisting role="example"><![CDATA[
#if G_GNUC_CHECK_VERSION(4, 8)
#endif
]]></programlisting></informalexample>
<para></para>
<refsect3 id="G-GNUC-CHECK-VERSION.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>major</para></entry>
<entry role="parameter_description"><para>major version to check against</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>minor</para></entry>
<entry role="parameter_description"><para>minor version to check against</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.42">2.42</link></para></refsect2>
<refsect2 id="G-GNUC-ALLOC-SIZE:CAPS" role="macro" condition="since:2.18">
<title>G_GNUC_ALLOC_SIZE()</title>
<indexterm zone="G-GNUC-ALLOC-SIZE:CAPS" role="2.18"><primary sortas="GNUC_ALLOC_SIZE">G_GNUC_ALLOC_SIZE</primary></indexterm>
<programlisting language="C">#define G_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
</programlisting>
<para>Expands to the GNU C <literal>alloc_size</literal> function attribute if the compiler
is a new enough gcc. This attribute tells the compiler that the
function returns a pointer to memory of a size that is specified
by the <parameter>xth</parameter>
 function parameter.</para>
<para>Place the attribute after the function declaration, just before the
semicolon.</para>
<informalexample><programlisting role="example"><![CDATA[
gpointer g_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
]]></programlisting></informalexample>
<para></para>
<para>See the <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute">GNU C documentation</ulink> for more details.</para>
<refsect3 id="G-GNUC-ALLOC-SIZE.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>x</para></entry>
<entry role="parameter_description"><para>the index of the argument specifying the allocation size</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.18">2.18</link></para></refsect2>
<refsect2 id="G-GNUC-ALLOC-SIZE2:CAPS" role="macro" condition="since:2.18">
<title>G_GNUC_ALLOC_SIZE2()</title>
<indexterm zone="G-GNUC-ALLOC-SIZE2:CAPS" role="2.18"><primary sortas="GNUC_ALLOC_SIZE2">G_GNUC_ALLOC_SIZE2</primary></indexterm>
<programlisting language="C">#define G_GNUC_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
</programlisting>
<para>Expands to the GNU C <literal>alloc_size</literal> function attribute if the compiler is a
new enough gcc. This attribute tells the compiler that the function returns
a pointer to memory of a size that is specified by the product of two
function parameters.</para>
<para>Place the attribute after the function declaration, just before the
semicolon.</para>
<informalexample><programlisting role="example"><![CDATA[
gpointer g_malloc_n (gsize n_blocks,
                     gsize n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1, 2);
]]></programlisting></informalexample>
<para></para>
<para>See the <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute">GNU C documentation</ulink> for more details.</para>
<refsect3 id="G-GNUC-ALLOC-SIZE2.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>x</para></entry>
<entry role="parameter_description"><para>the index of the argument specifying one factor of the allocation size</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>y</para></entry>
<entry role="parameter_description"><para>the index of the argument specifying the second factor of the allocation size</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.18">2.18</link></para></refsect2>
<refsect2 id="G-GNUC-DEPRECATED-FOR:CAPS" role="macro" condition="since:2.26">
<title>G_GNUC_DEPRECATED_FOR()</title>
<indexterm zone="G-GNUC-DEPRECATED-FOR:CAPS" role="2.26"><primary sortas="GNUC_DEPRECATED_FOR">G_GNUC_DEPRECATED_FOR</primary></indexterm>
<programlisting language="C">#define             G_GNUC_DEPRECATED_FOR(f)</programlisting>
<para>Like <link linkend="G-GNUC-DEPRECATED:CAPS"><literal>G_GNUC_DEPRECATED</literal></link>, but names the intended replacement for the
deprecated symbol if the version of gcc in use is new enough to support
custom deprecation messages.</para>
<para>Place the attribute after the declaration, just before the semicolon.</para>
<informalexample><programlisting role="example"><![CDATA[
int my_mistake (void) G_GNUC_DEPRECATED_FOR(my_replacement);
]]></programlisting></informalexample>
<para></para>
<para>See the <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-deprecated-function-attribute">GNU C documentation</ulink> for more details.</para>
<para>Note that if <parameter>f</parameter>
 is a macro, it will be expanded in the warning message.
You can enclose it in quotes to prevent this. (The quotes will show up
in the warning, but it's better than showing the macro expansion.)</para>
<refsect3 id="G-GNUC-DEPRECATED-FOR.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>f</para></entry>
<entry role="parameter_description"><para>the intended replacement for the deprecated symbol,
such as the name of a function</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.26">2.26</link></para></refsect2>
<refsect2 id="G-GNUC-PRINTF:CAPS" role="macro">
<title>G_GNUC_PRINTF()</title>
<indexterm zone="G-GNUC-PRINTF:CAPS"><primary sortas="GNUC_PRINTF">G_GNUC_PRINTF</primary></indexterm>
<programlisting language="C">#define             G_GNUC_PRINTF( format_idx, arg_idx )</programlisting>
<para>Expands to the GNU C <literal>format</literal> function attribute if the compiler is gcc.
This is used for declaring functions which take a variable number of
arguments, with the same syntax as <literal><link linkend="printf"><function>printf()</function></link></literal>. It allows the compiler
to type-check the arguments passed to the function.</para>
<para>Place the attribute after the function declaration, just before the
semicolon.</para>
<para>See the
<ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-Wformat-3288">GNU C documentation</ulink>
for more details.</para>
<informalexample><programlisting role="example"><![CDATA[
gint g_snprintf (gchar  *string,
                 gulong       n,
                 gchar const *format,
                 ...) G_GNUC_PRINTF (3, 4);
]]></programlisting></informalexample>
<para></para>
<refsect3 id="G-GNUC-PRINTF.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>format_idx</para></entry>
<entry role="parameter_description"><para>the index of the argument corresponding to the
format string (the arguments are numbered from 1)</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>arg_idx</para></entry>
<entry role="parameter_description"><para>the index of the first of the format arguments, or 0 if
there are no format arguments</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="G-GNUC-SCANF:CAPS" role="macro">
<title>G_GNUC_SCANF()</title>
<indexterm zone="G-GNUC-SCANF:CAPS"><primary sortas="GNUC_SCANF">G_GNUC_SCANF</primary></indexterm>
<programlisting language="C">#define             G_GNUC_SCANF( format_idx, arg_idx )</programlisting>
<para>Expands to the GNU C <literal>format</literal> function attribute if the compiler is gcc.
This is used for declaring functions which take a variable number of
arguments, with the same syntax as <literal><link linkend="scanf"><function>scanf()</function></link></literal>. It allows the compiler
to type-check the arguments passed to the function.</para>
<informalexample><programlisting role="example"><![CDATA[
int my_scanf (MyStream *stream,
              const char *format,
              ...) G_GNUC_SCANF (2, 3);
int my_vscanf (MyStream *stream,
               const char *format,
               va_list ap) G_GNUC_SCANF (2, 0);
]]></programlisting></informalexample>
<para></para>
<para>See the
<ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-Wformat-3288">GNU C documentation</ulink>
for details.</para>
<refsect3 id="G-GNUC-SCANF.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>format_idx</para></entry>
<entry role="parameter_description"><para>the index of the argument corresponding to
the format string (the arguments are numbered from 1)</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>arg_idx</para></entry>
<entry role="parameter_description"><para>the index of the first of the format arguments, or 0 if
there are no format arguments</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="G-GNUC-STRFTIME:CAPS" role="macro" condition="since:2.60">
<title>G_GNUC_STRFTIME()</title>
<indexterm zone="G-GNUC-STRFTIME:CAPS" role="2.60"><primary sortas="GNUC_STRFTIME">G_GNUC_STRFTIME</primary></indexterm>
<programlisting language="C">#define             G_GNUC_STRFTIME( format_idx )</programlisting>
<para>Expands to the GNU C <literal>strftime</literal> format function attribute if the compiler
is gcc. This is used for declaring functions which take a format argument
which is passed to <literal><link linkend="strftime"><function>strftime()</function></link></literal> or an API implementing its formats. It allows
the compiler check the format passed to the function.</para>
<informalexample><programlisting role="example"><![CDATA[
gsize my_strftime (MyBuffer *buffer,
                   const char *format,
                   const struct tm *tm) G_GNUC_STRFTIME (2);
]]></programlisting></informalexample>
<para></para>
<para>See the
<ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-Wformat-3288">GNU C documentation</ulink>
for details.</para>
<refsect3 id="G-GNUC-STRFTIME.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>format_idx</para></entry>
<entry role="parameter_description"><para>the index of the argument corresponding to
the format string (the arguments are numbered from 1)</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.60">2.60</link></para></refsect2>
<refsect2 id="G-GNUC-FORMAT:CAPS" role="macro">
<title>G_GNUC_FORMAT()</title>
<indexterm zone="G-GNUC-FORMAT:CAPS"><primary sortas="GNUC_FORMAT">G_GNUC_FORMAT</primary></indexterm>
<programlisting language="C">#define             G_GNUC_FORMAT( arg_idx )</programlisting>
<para>Expands to the GNU C <literal>format_arg</literal> function attribute if the compiler
is gcc. This function attribute specifies that a function takes a
format string for a <literal><link linkend="printf"><function>printf()</function></link></literal>, <literal><link linkend="scanf"><function>scanf()</function></link></literal>, <literal><link linkend="strftime"><function>strftime()</function></link></literal> or <literal><link linkend="strfmon"><function>strfmon()</function></link></literal> style
function and modifies it, so that the result can be passed to a <literal><link linkend="printf"><function>printf()</function></link></literal>,
<literal><link linkend="scanf"><function>scanf()</function></link></literal>, <literal><link linkend="strftime"><function>strftime()</function></link></literal> or <literal><link linkend="strfmon"><function>strfmon()</function></link></literal> style function (with the remaining
arguments to the format function the same as they would have been
for the unmodified string).</para>
<para>Place the attribute after the function declaration, just before the
semicolon.</para>
<para>See the <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-Wformat-nonliteral-1">GNU C documentation</ulink> for more details.</para>
<informalexample><programlisting role="example"><![CDATA[
gchar *g_dgettext (gchar *domain_name, gchar *msgid) G_GNUC_FORMAT (2);
]]></programlisting></informalexample>
<para></para>
<refsect3 id="G-GNUC-FORMAT.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>arg_idx</para></entry>
<entry role="parameter_description"><para>the index of the argument</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="G-DEPRECATED-FOR:CAPS" role="macro" condition="since:2.32">
<title>G_DEPRECATED_FOR()</title>
<indexterm zone="G-DEPRECATED-FOR:CAPS" role="2.32"><primary sortas="DEPRECATED_FOR">G_DEPRECATED_FOR</primary></indexterm>
<programlisting language="C">#define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead")))
</programlisting>
<para>This macro is similar to <link linkend="G-GNUC-DEPRECATED-FOR:CAPS"><literal>G_GNUC_DEPRECATED_FOR</literal></link>, and can be used to mark
functions declarations as deprecated. Unlike <link linkend="G-GNUC-DEPRECATED-FOR:CAPS"><literal>G_GNUC_DEPRECATED_FOR</literal></link>, it
is meant to be portable across different compilers and must be placed
before the function declaration.</para>
<informalexample><programlisting role="example"><![CDATA[
G_DEPRECATED_FOR(my_replacement)
int my_mistake (void);
]]></programlisting></informalexample>
<para></para>
<refsect3 id="G-DEPRECATED-FOR.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>f</para></entry>
<entry role="parameter_description"><para>the name of the function that this function was deprecated for</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.32">2.32</link></para></refsect2>
<refsect2 id="G-UNAVAILABLE:CAPS" role="macro" condition="since:2.32">
<title>G_UNAVAILABLE()</title>
<indexterm zone="G-UNAVAILABLE:CAPS" role="2.32"><primary sortas="UNAVAILABLE">G_UNAVAILABLE</primary></indexterm>
<programlisting language="C">#define G_UNAVAILABLE(maj,min) __attribute__((deprecated("Not available before " #maj "." #min)))
</programlisting>
<para>This macro can be used to mark a function declaration as unavailable.
It must be placed before the function declaration. Use of a function
that has been annotated with this macros will produce a compiler warning.</para>
<refsect3 id="G-UNAVAILABLE.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>maj</para></entry>
<entry role="parameter_description"><para>the major version that introduced the symbol</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>min</para></entry>
<entry role="parameter_description"><para>the minor version that introduced the symbol</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><para role="since">Since: <link linkend="api-index-2.32">2.32</link></para></refsect2>
<refsect2 id="G-LIKELY:CAPS" role="macro" condition="since:2.2">
<title>G_LIKELY()</title>
<indexterm zone="G-LIKELY:CAPS" role="2.2"><primary sortas="LIKELY">G_LIKELY</primary></indexterm>
<programlisting language="C">#define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 1))
</programlisting>
<para>Hints the compiler that the expression is likely to evaluate to
a true value. The compiler may use this information for optimizations.</para>
<informalexample><programlisting role="example"><![CDATA[
if (G_LIKELY (random () != 1))
  g_print ("not one");
]]></programlisting></informalexample>
<para></para>
<refsect3 id="G-LIKELY.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>expr</para></entry>
<entry role="parameter_description"><para>the expression</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="G-LIKELY.returns" role="returns">
<title>Returns</title>
<para> the value of <parameter>expr</parameter>
</para>
</refsect3><para role="since">Since: <link linkend="api-index-2.2">2.2</link></para></refsect2>
<refsect2 id="G-UNLIKELY:CAPS" role="macro" condition="since:2.2">
<title>G_UNLIKELY()</title>
<indexterm zone="G-UNLIKELY:CAPS" role="2.2"><primary sortas="UNLIKELY">G_UNLIKELY</primary></indexterm>
<programlisting language="C">#define G_UNLIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 0))
</programlisting>
<para>Hints the compiler that the expression is unlikely to evaluate to
a true value. The compiler may use this information for optimizations.</para>
<informalexample><programlisting role="example"><![CDATA[
if (G_UNLIKELY (random () == 1))
  g_print ("a random one");
]]></programlisting></informalexample>
<para></para>
<refsect3 id="G-UNLIKELY.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>expr</para></entry>
<entry role="parameter_description"><para>the expression</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="G-UNLIKELY.returns" role="returns">
<title>Returns</title>
<para> the value of <parameter>expr</parameter>
</para>
</refsect3><para role="since">Since: <link linkend="api-index-2.2">2.2</link></para></refsect2>

</refsect1>
<refsect1 id="glib-Miscellaneous-Macros.other_details" role="details">
<title role="details.title">Types and Values</title>
<refsect2 id="G-INLINE-FUNC:CAPS" role="macro" condition="deprecated:2.48: Use &quot;static inline&quot; instead">
<title>G_INLINE_FUNC</title>
<indexterm zone="G-INLINE-FUNC:CAPS" role="deprecated"><primary sortas="INLINE_FUNC">G_INLINE_FUNC</primary></indexterm>
<programlisting language="C">#  define G_INLINE_FUNC extern GLIB_DEPRECATED_MACRO_IN_2_48_FOR(static inline)
</programlisting>
<warning><para><literal>G_INLINE_FUNC</literal> has been deprecated since version 2.48 and should not be used in newly-written code.</para> <para>Use "static inline" instead</para>
</warning>
<para>This macro used to be used to conditionally define inline functions
in a compatible way before this feature was supported in all
compilers.  These days, GLib requires inlining support from the
compiler, so your GLib-using programs can safely assume that the
"inline" keyword works properly.</para>
<para>Never use this macro anymore.  Just say "static inline".</para>
</refsect2>
<refsect2 id="g-autofree" role="macro" condition="since:2.44">
<title>g_autofree</title>
<indexterm zone="g-autofree" role="2.44"><primary sortas="autofree">g_autofree</primary></indexterm>
<programlisting language="C">#define             g_autofree</programlisting>
<para>Macro to add an attribute to pointer variable to ensure automatic
cleanup using <link linkend="g-free"><function>g_free()</function></link>.</para>
<para>This macro differs from <link linkend="g-autoptr"><function>g_autoptr()</function></link> in that it is an attribute supplied
before the type name, rather than wrapping the type definition.  Instead
of using a type-specific lookup, this macro always calls <link linkend="g-free"><function>g_free()</function></link> directly.</para>
<para>This means it's useful for any type that is returned from
<link linkend="g-malloc"><function>g_malloc()</function></link>.</para>
<para>Otherwise, this macro has similar constraints as <link linkend="g-autoptr"><function>g_autoptr()</function></link>: only
supported on GCC and clang, the variable must be initialized, etc.</para>
<informalexample><programlisting role="example"><![CDATA[
gboolean
operate_on_malloc_buf (void)
{
  g_autofree guint8* membuf = NULL;

  membuf = g_malloc (8192);

  // Some computation on membuf

  // membuf will be automatically freed here
  return TRUE;
}
]]></programlisting></informalexample>
<para></para>
<para role="since">Since: <link linkend="api-index-2.44">2.44</link></para></refsect2>
<refsect2 id="G-STMT-START:CAPS" role="macro">
<title>G_STMT_START</title>
<indexterm zone="G-STMT-START:CAPS"><primary sortas="STMT_START">G_STMT_START</primary></indexterm>
<programlisting language="C">#define G_STMT_START  do
</programlisting>
<para>Used within multi-statement macros so that they can be used in places
where only one statement is expected by the compiler.</para>
</refsect2>
<refsect2 id="G-STMT-END:CAPS" role="macro">
<title>G_STMT_END</title>
<indexterm zone="G-STMT-END:CAPS"><primary sortas="STMT_END">G_STMT_END</primary></indexterm>
<programlisting language="C">#define             G_STMT_END</programlisting>
<para>Used within multi-statement macros so that they can be used in places
where only one statement is expected by the compiler.</para>
</refsect2>
<refsect2 id="G-BEGIN-DECLS:CAPS" role="macro">
<title>G_BEGIN_DECLS</title>
<indexterm zone="G-BEGIN-DECLS:CAPS"><primary sortas="BEGIN_DECLS">G_BEGIN_DECLS</primary></indexterm>
<programlisting language="C">#define G_BEGIN_DECLS  extern "C" {
</programlisting>
<para>Used (along with <link linkend="G-END-DECLS:CAPS"><type>G_END_DECLS</type></link>) to bracket header files. If the
compiler in use is a C++ compiler, adds extern "C"
around the header.</para>
</refsect2>
<refsect2 id="G-END-DECLS:CAPS" role="macro">
<title>G_END_DECLS</title>
<indexterm zone="G-END-DECLS:CAPS"><primary sortas="END_DECLS">G_END_DECLS</primary></indexterm>
<programlisting language="C">#define G_END_DECLS    }
</programlisting>
<para>Used (along with <link linkend="G-BEGIN-DECLS:CAPS"><type>G_BEGIN_DECLS</type></link>) to bracket header files. If the
compiler in use is a C++ compiler, adds extern "C"
around the header.</para>
</refsect2>
<refsect2 id="G-GNUC-EXTENSION:CAPS" role="macro">
<title>G_GNUC_EXTENSION</title>
<indexterm zone="G-GNUC-EXTENSION:CAPS"><primary sortas="GNUC_EXTENSION">G_GNUC_EXTENSION</primary></indexterm>
<programlisting language="C">#define G_GNUC_EXTENSION __extension__
</programlisting>
<para>Expands to __extension__ when gcc is used as the compiler. This simply
tells gcc not to warn about the following non-standard code when compiling
with the <literal>-pedantic</literal> option.</para>
</refsect2>
<refsect2 id="G-GNUC-CONST:CAPS" role="macro">
<title>G_GNUC_CONST</title>
<indexterm zone="G-GNUC-CONST:CAPS"><primary sortas="GNUC_CONST">G_GNUC_CONST</primary></indexterm>
<programlisting language="C">#define             G_GNUC_CONST</programlisting>
<para>Expands to the GNU C <literal>const</literal> function attribute if the compiler is gcc.
Declaring a function as <literal>const</literal> enables better optimization of calls to
the function. A <literal>const</literal> function doesn't examine any values except its
parameters, and has no effects except its return value.</para>
<para>Place the attribute after the declaration, just before the semicolon.</para>
<informalexample><programlisting role="example"><![CDATA[
gchar g_ascii_tolower (gchar c) G_GNUC_CONST;
]]></programlisting></informalexample>
<para></para>
<para>See the <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-const-function-attribute">GNU C documentation</ulink> for more details.</para>
<para>A function that has pointer arguments and examines the data pointed to
must not be declared <literal>const</literal>. Likewise, a function that calls a non-<literal>const</literal>
function usually must not be <literal>const</literal>. It doesn't make sense for a <literal>const</literal>
function to return <literal>void</literal>.</para>
</refsect2>
<refsect2 id="G-GNUC-PURE:CAPS" role="macro">
<title>G_GNUC_PURE</title>
<indexterm zone="G-GNUC-PURE:CAPS"><primary sortas="GNUC_PURE">G_GNUC_PURE</primary></indexterm>
<programlisting language="C">#define G_GNUC_PURE __attribute__((__pure__))
</programlisting>
<para>Expands to the GNU C <literal>pure</literal> function attribute if the compiler is gcc.
Declaring a function as <literal>pure</literal> enables better optimization of calls to
the function. A <literal>pure</literal> function has no effects except its return value
and the return value depends only on the parameters and/or global
variables.</para>
<para>Place the attribute after the declaration, just before the semicolon.</para>
<informalexample><programlisting role="example"><![CDATA[
gboolean g_type_check_value (const GValue *value) G_GNUC_PURE;
]]></programlisting></informalexample>
<para></para>
<para>See the <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-pure-function-attribute">GNU C documentation</ulink> for more details.</para>
</refsect2>
<refsect2 id="G-GNUC-MALLOC:CAPS" role="macro" condition="since:2.6">
<title>G_GNUC_MALLOC</title>
<indexterm zone="G-GNUC-MALLOC:CAPS" role="2.6"><primary sortas="GNUC_MALLOC">G_GNUC_MALLOC</primary></indexterm>
<programlisting language="C">#define G_GNUC_MALLOC __attribute__((__malloc__))
</programlisting>
<para>Expands to the
<ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-functions-that-behave-like-malloc">GNU C <literal>malloc</literal> function attribute</ulink>
if the compiler is gcc.
Declaring a function as <literal>malloc</literal> enables better optimization of the function,
but must only be done if the allocation behaviour of the function is fully
understood, otherwise miscompilation can result.</para>
<para>A function can have the <literal>malloc</literal> attribute if it returns a pointer which is
guaranteed to not alias with any other pointer valid when the function
returns, and moreover no pointers to valid objects occur in any storage
addressed by the returned pointer.</para>
<para>In practice, this means that <literal>G_GNUC_MALLOC</literal> can be used with any function
which returns unallocated or zeroed-out memory, but not with functions which
return initialised structures containing other pointers, or with functions
that reallocate memory. This definition changed in GLib 2.58 to match the
stricter definition introduced around GCC 5.</para>
<para>Place the attribute after the declaration, just before the semicolon.</para>
<informalexample><programlisting role="example"><![CDATA[
gpointer g_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
]]></programlisting></informalexample>
<para></para>
<para>See the
<ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-functions-that-behave-like-malloc">GNU C documentation</ulink>
for more details.</para>
<para role="since">Since: <link linkend="api-index-2.6">2.6</link></para></refsect2>
<refsect2 id="G-GNUC-DEPRECATED:CAPS" role="macro" condition="since:2.2">
<title>G_GNUC_DEPRECATED</title>
<indexterm zone="G-GNUC-DEPRECATED:CAPS" role="2.2"><primary sortas="GNUC_DEPRECATED">G_GNUC_DEPRECATED</primary></indexterm>
<programlisting language="C">#define G_GNUC_DEPRECATED __attribute__((__deprecated__))
</programlisting>
<para>Expands to the GNU C <literal>deprecated</literal> attribute if the compiler is gcc.
It can be used to mark <literal>typedef</literal>s, variables and functions as deprecated.
When called with the <literal>-Wdeprecated-declarations</literal> option,
gcc will generate warnings when deprecated interfaces are used.</para>
<para>Place the attribute after the declaration, just before the semicolon.</para>
<informalexample><programlisting role="example"><![CDATA[
int my_mistake (void) G_GNUC_DEPRECATED;
]]></programlisting></informalexample>
<para></para>
<para>See the <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-deprecated-function-attribute">GNU C documentation</ulink> for more details.</para>
<para role="since">Since: <link linkend="api-index-2.2">2.2</link></para></refsect2>
<refsect2 id="G-GNUC-BEGIN-IGNORE-DEPRECATIONS:CAPS" role="macro" condition="since:2.32">
<title>G_GNUC_BEGIN_IGNORE_DEPRECATIONS</title>
<indexterm zone="G-GNUC-BEGIN-IGNORE-DEPRECATIONS:CAPS" role="2.32"><primary sortas="GNUC_BEGIN_IGNORE_DEPRECATIONS">G_GNUC_BEGIN_IGNORE_DEPRECATIONS</primary></indexterm>
<programlisting language="C">#define             G_GNUC_BEGIN_IGNORE_DEPRECATIONS</programlisting>
<para>Tells gcc (if it is a new enough version) to temporarily stop emitting
warnings when functions marked with <link linkend="G-GNUC-DEPRECATED:CAPS"><literal>G_GNUC_DEPRECATED</literal></link> or
<link linkend="G-GNUC-DEPRECATED-FOR:CAPS"><literal>G_GNUC_DEPRECATED_FOR</literal></link> are called. This is useful for when you have
one deprecated function calling another one, or when you still have
regression tests for deprecated functions.</para>
<para>Use <link linkend="G-GNUC-END-IGNORE-DEPRECATIONS:CAPS"><literal>G_GNUC_END_IGNORE_DEPRECATIONS</literal></link> to begin warning again. (If you
are not compiling with <literal>-Wdeprecated-declarations</literal> then neither macro
has any effect.)</para>
<para>This macro can be used either inside or outside of a function body,
but must appear on a line by itself. Both this macro and the corresponding
<link linkend="G-GNUC-END-IGNORE-DEPRECATIONS:CAPS"><literal>G_GNUC_END_IGNORE_DEPRECATIONS</literal></link> are considered statements, so they
should not be used around branching or loop conditions; for instance,
this use is invalid:</para>
<informalexample><programlisting role="example"><![CDATA[
  G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  if (check == some_deprecated_function ())
  G_GNUC_END_IGNORE_DEPRECATIONS
    {
      do_something ();
    }
]]></programlisting></informalexample>
<para></para>
<para>and you should move the deprecated section outside the condition</para>
<informalexample><programlisting role="example"><![CDATA[

  // Solution A
  some_data_t *res;

  G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  res = some_deprecated_function ();
  G_GNUC_END_IGNORE_DEPRECATIONS

  if (check == res)
    {
      do_something ();
    }

  // Solution B
  G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  if (check == some_deprecated_function ())
    {
      do_something ();
    }
  G_GNUC_END_IGNORE_DEPRECATIONS
]]></programlisting></informalexample>
<para></para>
<informalexample><programlisting role="example"><![CDATA[
static void
test_deprecated_function (void)
{
  G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  g_assert_cmpint (my_mistake (), ==, 42);
  G_GNUC_END_IGNORE_DEPRECATIONS
}
]]></programlisting></informalexample>
<para></para>
<para role="since">Since: <link linkend="api-index-2.32">2.32</link></para></refsect2>
<refsect2 id="G-GNUC-END-IGNORE-DEPRECATIONS:CAPS" role="macro" condition="since:2.32">
<title>G_GNUC_END_IGNORE_DEPRECATIONS</title>
<indexterm zone="G-GNUC-END-IGNORE-DEPRECATIONS:CAPS" role="2.32"><primary sortas="GNUC_END_IGNORE_DEPRECATIONS">G_GNUC_END_IGNORE_DEPRECATIONS</primary></indexterm>
<programlisting language="C">#define             G_GNUC_END_IGNORE_DEPRECATIONS</programlisting>
<para>Undoes the effect of <link linkend="G-GNUC-BEGIN-IGNORE-DEPRECATIONS:CAPS"><literal>G_GNUC_BEGIN_IGNORE_DEPRECATIONS</literal></link>, telling
gcc to begin outputting warnings again (assuming those warnings
had been enabled to begin with).</para>
<para>This macro can be used either inside or outside of a function body,
but must appear on a line by itself.</para>
<para role="since">Since: <link linkend="api-index-2.32">2.32</link></para></refsect2>
<refsect2 id="G-GNUC-NORETURN:CAPS" role="macro">
<title>G_GNUC_NORETURN</title>
<indexterm zone="G-GNUC-NORETURN:CAPS"><primary sortas="GNUC_NORETURN">G_GNUC_NORETURN</primary></indexterm>
<programlisting language="C">#define             G_GNUC_NORETURN</programlisting>
<para>Expands to the GNU C <literal>noreturn</literal> function attribute if the compiler is gcc.
It is used for declaring functions which never return. It enables
optimization of the function, and avoids possible compiler warnings.</para>
<para>Place the attribute after the declaration, just before the semicolon.</para>
<informalexample><programlisting role="example"><![CDATA[
void g_abort (void) G_GNUC_NORETURN;
]]></programlisting></informalexample>
<para></para>
<para>See the <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute">GNU C documentation</ulink> for more details.</para>
</refsect2>
<refsect2 id="G-GNUC-FALLTHROUGH:CAPS" role="macro" condition="since:2.60">
<title>G_GNUC_FALLTHROUGH</title>
<indexterm zone="G-GNUC-FALLTHROUGH:CAPS" role="2.60"><primary sortas="GNUC_FALLTHROUGH">G_GNUC_FALLTHROUGH</primary></indexterm>
<programlisting language="C">#define G_GNUC_FALLTHROUGH __attribute__((fallthrough))
</programlisting>
<para>Expands to the GNU C <literal>fallthrough</literal> statement attribute if the compiler supports it.
This allows declaring case statement to explicitly fall through in switch
statements. To enable this feature, use <literal>-Wimplicit-fallthrough</literal> during
compilation.</para>
<para>Put the attribute right before the case statement you want to fall through
to.</para>
<informalexample><programlisting role="example"><![CDATA[
switch (foo)
  {
    case 1:
      g_message ("it's 1");
      G_GNUC_FALLTHROUGH;
    case 2:
      g_message ("it's either 1 or 2");
      break;
  }
]]></programlisting></informalexample>
<para></para>
<para>See the <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#index-fallthrough-statement-attribute">GNU C documentation</ulink> for more details.</para>
<para role="since">Since: <link linkend="api-index-2.60">2.60</link></para></refsect2>
<refsect2 id="G-GNUC-UNUSED:CAPS" role="macro">
<title>G_GNUC_UNUSED</title>
<indexterm zone="G-GNUC-UNUSED:CAPS"><primary sortas="GNUC_UNUSED">G_GNUC_UNUSED</primary></indexterm>
<programlisting language="C">#define             G_GNUC_UNUSED</programlisting>
<para>Expands to the GNU C <literal>unused</literal> function attribute if the compiler is gcc.
It is used for declaring functions and arguments which may never be used.
It avoids possible compiler warnings.</para>
<para>For functions, place the attribute after the declaration, just before the
semicolon. For arguments, place the attribute at the beginning of the
argument declaration.</para>
<informalexample><programlisting role="example"><![CDATA[
void my_unused_function (G_GNUC_UNUSED gint unused_argument,
                         gint other_argument) G_GNUC_UNUSED;
]]></programlisting></informalexample>
<para></para>
<para>See the <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-unused-function-attribute">GNU C documentation</ulink> for more details.</para>
</refsect2>
<refsect2 id="G-GNUC-NULL-TERMINATED:CAPS" role="macro" condition="since:2.8">
<title>G_GNUC_NULL_TERMINATED</title>
<indexterm zone="G-GNUC-NULL-TERMINATED:CAPS" role="2.8"><primary sortas="GNUC_NULL_TERMINATED">G_GNUC_NULL_TERMINATED</primary></indexterm>
<programlisting language="C">#define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
</programlisting>
<para>Expands to the GNU C <literal>sentinel</literal> function attribute if the compiler is gcc.
This function attribute only applies to variadic functions and instructs
the compiler to check that the argument list is terminated with an
explicit <link linkend="NULL:CAPS"><literal>NULL</literal></link>.</para>
<para>Place the attribute after the declaration, just before the semicolon.</para>
<informalexample><programlisting role="example"><![CDATA[
gchar *g_strconcat (const gchar *string1,
                    ...) G_GNUC_NULL_TERMINATED;
]]></programlisting></informalexample>
<para></para>
<para>See the <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-sentinel-function-attribute">GNU C documentation</ulink> for more details.</para>
<para role="since">Since: <link linkend="api-index-2.8">2.8</link></para></refsect2>
<refsect2 id="G-GNUC-WARN-UNUSED-RESULT:CAPS" role="macro" condition="since:2.10">
<title>G_GNUC_WARN_UNUSED_RESULT</title>
<indexterm zone="G-GNUC-WARN-UNUSED-RESULT:CAPS" role="2.10"><primary sortas="GNUC_WARN_UNUSED_RESULT">G_GNUC_WARN_UNUSED_RESULT</primary></indexterm>
<programlisting language="C">#define G_GNUC_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
</programlisting>
<para>Expands to the GNU C <literal>warn_unused_result</literal> function attribute if the compiler
is gcc. This function attribute makes the compiler emit a warning if the
result of a function call is ignored.</para>
<para>Place the attribute after the declaration, just before the semicolon.</para>
<informalexample><programlisting role="example"><![CDATA[
GList *g_list_append (GList *list,
                      gpointer data) G_GNUC_WARN_UNUSED_RESULT;
]]></programlisting></informalexample>
<para></para>
<para>See the <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-warn_005funused_005fresult-function-attribute">GNU C documentation</ulink> for more details.</para>
<para role="since">Since: <link linkend="api-index-2.10">2.10</link></para></refsect2>
<refsect2 id="G-GNUC-FUNCTION:CAPS" role="macro" condition="deprecated:2.16: Use G_STRFUNC() instead">
<title>G_GNUC_FUNCTION</title>
<indexterm zone="G-GNUC-FUNCTION:CAPS" role="deprecated"><primary sortas="GNUC_FUNCTION">G_GNUC_FUNCTION</primary></indexterm>
<programlisting language="C">#define G_GNUC_FUNCTION         __FUNCTION__ GLIB_DEPRECATED_MACRO_IN_2_26_FOR(G_STRFUNC)
</programlisting>
<warning><para><literal>G_GNUC_FUNCTION</literal> has been deprecated since version 2.16 and should not be used in newly-written code.</para> <para>Use <link linkend="G-STRFUNC:CAPS"><function>G_STRFUNC()</function></link> instead</para>
</warning>
<para>Expands to "" on all modern compilers, and to  __FUNCTION__ on gcc
version 2.x. Don't use it.</para>
</refsect2>
<refsect2 id="G-GNUC-PRETTY-FUNCTION:CAPS" role="macro" condition="deprecated:2.16: Use G_STRFUNC() instead">
<title>G_GNUC_PRETTY_FUNCTION</title>
<indexterm zone="G-GNUC-PRETTY-FUNCTION:CAPS" role="deprecated"><primary sortas="GNUC_PRETTY_FUNCTION">G_GNUC_PRETTY_FUNCTION</primary></indexterm>
<programlisting language="C">#define G_GNUC_PRETTY_FUNCTION  __PRETTY_FUNCTION__ GLIB_DEPRECATED_MACRO_IN_2_26_FOR(G_STRFUNC)
</programlisting>
<warning><para><literal>G_GNUC_PRETTY_FUNCTION</literal> has been deprecated since version 2.16 and should not be used in newly-written code.</para> <para>Use <link linkend="G-STRFUNC:CAPS"><function>G_STRFUNC()</function></link> instead</para>
</warning>
<para>Expands to "" on all modern compilers, and to __PRETTY_FUNCTION__
on gcc version 2.x. Don't use it.</para>
</refsect2>
<refsect2 id="G-GNUC-NO-INLINE:CAPS" role="macro" condition="since:2.58">
<title>G_GNUC_NO_INLINE</title>
<indexterm zone="G-GNUC-NO-INLINE:CAPS" role="2.58"><primary sortas="GNUC_NO_INLINE">G_GNUC_NO_INLINE</primary></indexterm>
<programlisting language="C">#define G_GNUC_NO_INLINE __attribute__((noinline))
</programlisting>
<para>Expands to the GNU C <literal>noinline</literal> function attribute if the compiler is gcc.
If the compiler is not gcc, this macro expands to nothing.</para>
<para>Declaring a function as <literal>noinline</literal> prevents the function from being
considered for inlining.</para>
<para>The attribute may be placed before the declaration or definition,
right before the <literal>static</literal> keyword.</para>
<informalexample><programlisting role="example"><![CDATA[
G_GNUC_NO_INLINE
static int
do_not_inline_this (void)
{
  ...
}
]]></programlisting></informalexample>
<para></para>
<para>See the
<ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noinline-function-attribute">GNU C documentation</ulink>
for more details.</para>
<para role="since">Since: <link linkend="api-index-2.58">2.58</link></para></refsect2>
<refsect2 id="G-GNUC-NO-INSTRUMENT:CAPS" role="macro">
<title>G_GNUC_NO_INSTRUMENT</title>
<indexterm zone="G-GNUC-NO-INSTRUMENT:CAPS"><primary sortas="GNUC_NO_INSTRUMENT">G_GNUC_NO_INSTRUMENT</primary></indexterm>
<programlisting language="C">#define             G_GNUC_NO_INSTRUMENT</programlisting>
<para>Expands to the GNU C <literal>no_instrument_function</literal> function attribute if the
compiler is gcc. Functions with this attribute will not be instrumented
for profiling, when the compiler is called with the
<literal>-finstrument-functions</literal> option.</para>
<para>Place the attribute after the declaration, just before the semicolon.</para>
<informalexample><programlisting role="example"><![CDATA[
int do_uninteresting_things (void) G_GNUC_NO_INSTRUMENT;
]]></programlisting></informalexample>
<para></para>
<para>See the <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005finstrument_005ffunction-function-attribute">GNU C documentation</ulink> for more details.</para>
</refsect2>
<refsect2 id="G-HAVE-GNUC-VISIBILITY:CAPS" role="macro">
<title>G_HAVE_GNUC_VISIBILITY</title>
<indexterm zone="G-HAVE-GNUC-VISIBILITY:CAPS"><primary sortas="HAVE_GNUC_VISIBILITY">G_HAVE_GNUC_VISIBILITY</primary></indexterm>
<programlisting language="C">#define G_HAVE_GNUC_VISIBILITY 1
</programlisting>
<para>Defined to 1 if gcc-style visibility handling is supported.</para>
</refsect2>
<refsect2 id="G-GNUC-INTERNAL:CAPS" role="macro" condition="since:2.6">
<title>G_GNUC_INTERNAL</title>
<indexterm zone="G-GNUC-INTERNAL:CAPS" role="2.6"><primary sortas="GNUC_INTERNAL">G_GNUC_INTERNAL</primary></indexterm>
<programlisting language="C">#define G_GNUC_INTERNAL __attribute__((visibility("hidden")))
</programlisting>
<para>This attribute can be used for marking library functions as being used
internally to the library only, which may allow the compiler to handle
function calls more efficiently. Note that static functions do not need
to be marked as internal in this way. See the GNU C documentation for
details.</para>
<para>When using a compiler that supports the GNU C hidden visibility attribute,
this macro expands to __attribute__((visibility("hidden"))).
When using the Sun Studio compiler, it expands to __hidden.</para>
<para>Note that for portability, the attribute should be placed before the
function declaration. While GCC allows the macro after the declaration,
Sun Studio does not.</para>
<informalexample><programlisting role="example"><![CDATA[
G_GNUC_INTERNAL
void _g_log_fallback_handler (const gchar    *log_domain,
                              GLogLevelFlags  log_level,
                              const gchar    *message,
                              gpointer        unused_data);
]]></programlisting></informalexample>
<para></para>
<para role="since">Since: <link linkend="api-index-2.6">2.6</link></para></refsect2>
<refsect2 id="G-GNUC-MAY-ALIAS:CAPS" role="macro" condition="since:2.14">
<title>G_GNUC_MAY_ALIAS</title>
<indexterm zone="G-GNUC-MAY-ALIAS:CAPS" role="2.14"><primary sortas="GNUC_MAY_ALIAS">G_GNUC_MAY_ALIAS</primary></indexterm>
<programlisting language="C">#define G_GNUC_MAY_ALIAS __attribute__((may_alias))
</programlisting>
<para>Expands to the GNU C <literal>may_alias</literal> type attribute if the compiler is gcc.
Types with this attribute will not be subjected to type-based alias
analysis, but are assumed to alias with any other type, just like <literal>char</literal>.</para>
<para>See the <ulink url="https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-may_005falias-type-attribute">GNU C documentation</ulink> for details.</para>
<para role="since">Since: <link linkend="api-index-2.14">2.14</link></para></refsect2>
<refsect2 id="G-DEPRECATED:CAPS" role="macro" condition="since:2.32">
<title>G_DEPRECATED</title>
<indexterm zone="G-DEPRECATED:CAPS" role="2.32"><primary sortas="DEPRECATED">G_DEPRECATED</primary></indexterm>
<programlisting language="C">#define G_DEPRECATED __attribute__((__deprecated__))
</programlisting>
<para>This macro is similar to <link linkend="G-GNUC-DEPRECATED:CAPS"><literal>G_GNUC_DEPRECATED</literal></link>, and can be used to mark
functions declarations as deprecated. Unlike <link linkend="G-GNUC-DEPRECATED:CAPS"><literal>G_GNUC_DEPRECATED</literal></link>, it is
meant to be portable across different compilers and must be placed
before the function declaration.</para>
<informalexample><programlisting role="example"><![CDATA[
G_DEPRECATED
int my_mistake (void);
]]></programlisting></informalexample>
<para></para>
<para role="since">Since: <link linkend="api-index-2.32">2.32</link></para></refsect2>
<refsect2 id="G-STRLOC:CAPS" role="macro">
<title>G_STRLOC</title>
<indexterm zone="G-STRLOC:CAPS"><primary sortas="STRLOC">G_STRLOC</primary></indexterm>
<programlisting language="C">#define G_STRLOC&#160;__FILE__ ":" G_STRINGIFY (__LINE__) ":" __PRETTY_FUNCTION__ "()"
</programlisting>
<para>Expands to a string identifying the current code position.</para>
</refsect2>
<refsect2 id="G-STRFUNC:CAPS" role="macro" condition="since:2.4">
<title>G_STRFUNC</title>
<indexterm zone="G-STRFUNC:CAPS" role="2.4"><primary sortas="STRFUNC">G_STRFUNC</primary></indexterm>
<programlisting language="C">#define G_STRFUNC     ((const char*) (__PRETTY_FUNCTION__))
</programlisting>
<para>Expands to a string identifying the current function.</para>
<para role="since">Since: <link linkend="api-index-2.4">2.4</link></para></refsect2>

</refsect1>

</refentry>
