Integrate gnulib vasnprintf().
[platform/upstream/glib.git] / docs / reference / glib / tmpl / macros_misc.sgml
index 276a463..d66ff4f 100644 (file)
@@ -42,7 +42,8 @@ only one statement is expected by the compiler.
 <!-- ##### MACRO G_BEGIN_DECLS ##### -->
 <para>
 Used (along with #G_END_DECLS) to bracket header files. If the
-compiler in use is a C++ compiler, adds 'extern "C"' around the header.
+compiler in use is a C++ compiler, adds <literal>extern "C"</literal> 
+around the header.
 </para>
 
 
@@ -77,6 +78,7 @@ yourself, because this macro may use <function>memmove()</function> and GLib
 does not include <function>string.h</function> for you.
 </para>
 
+<!-- # Unused Parameters # -->
 @ap1: the <type>va_list</type> variable to place a copy of @ap2 in.
 @ap2: a <type>va_list</type>.
 
@@ -91,16 +93,48 @@ Accepts a macro or a string and converts it into a string.
 
 <!-- ##### MACRO G_GNUC_EXTENSION ##### -->
 <para>
-Expands to <literal>__extension__</literal> when GNU C is used as the compiler.
-This simply tells GNU C not to warn about the following non-standard code
-when compiling with the <literal>-pedantic</literal> option.
+Expands to <literal>__extension__</literal> when <command>gcc</command> is 
+used as the compiler.
+This simply tells <command>gcc</command> not to warn about the following non-standard code
+when compiling with the <option>-pedantic</option> option.
+</para>
+
+
+
+<!-- ##### MACRO G_GNUC_CONST ##### -->
+<para>
+Expands to the GNU C <literal>const</literal> function attribute if the compiler is <command>gcc</command>.
+Declaring a function as const enables better optimization of the function.
+A const function doesn't examine any values except its parameters,
+and has no effects except its return value.
+See the GNU C documentation for details. 
+</para>
+<note><para>
+A function that has pointer arguments and examines the data pointed to 
+must <emphasis>not</emphasis> be declared const. Likewise, a function that 
+calls a non-const function usually must not be const. It doesn't make sense 
+for a const function to return void.
+</para></note>
+
+
+
+<!-- ##### MACRO G_GNUC_DEPRECATED ##### -->
+<para>
+Expands to the GNU C <literal>deprecated</literal> attribute if the compiler 
+is <command>gcc</command>.
+It can be used to mark typedefs, variables and functions as deprecated. 
+When called with the <option>-Wdeprecated</option> option, the compiler will 
+generate warnings when deprecated interfaces are used.
+See the GNU C documentation for details. 
 </para>
 
+@Since: 2.2
 
 
 <!-- ##### MACRO G_GNUC_NORETURN ##### -->
 <para>
-Expands to the GNU C noreturn function attribute if the compiler is GNU C.
+Expands to the GNU C <literal>noreturn</literal> function attribute if the 
+compiler is <command>gcc</command>.
 It is used for declaring functions which never return.
 It enables optimization of the function, and avoids possible compiler
 warnings. See the GNU C documentation for details. 
@@ -110,7 +144,7 @@ warnings. See the GNU C documentation for details.
 
 <!-- ##### MACRO G_GNUC_UNUSED ##### -->
 <para>
-Expands to the GNU C unused function attribute if the compiler is GNU C.
+Expands to the GNU C <literal>unused</literal> function attribute if the compiler is <command>gcc</command>.
 It is used for declaring functions which may never be used.
 It avoids possible compiler warnings. See the GNU C documentation for details. 
 </para>
@@ -119,7 +153,7 @@ It avoids possible compiler warnings. See the GNU C documentation for details.
 
 <!-- ##### MACRO G_GNUC_PURE ##### -->
 <para>
-Expands to the GNU C pure function attribute if the compiler is GNU C.
+Expands to the GNU C <literal>pure</literal> function attribute if the compiler is <command>gcc</command>.
 Declaring a function as pure enables better optimization of the function.
 A pure function has no effects except its return value and the return 
 value depends only on the parameters and/or global variables.
@@ -127,20 +161,10 @@ See the GNU C documentation for details.
 </para>
 
 
-<!-- ##### MACRO G_GNUC_CONST ##### -->
-<para>
-Expands to the GNU C const function attribute if the compiler is GNU C.
-Declaring a function as const enables better optimization of the function.
-A const function doesn't examine any values except its parameters,
-and has no effects except its return value.
-See the GNU C documentation for details. 
-</para>
-
-
 
 <!-- ##### MACRO G_GNUC_PRINTF ##### -->
 <para>
-Expands to the GNU C format function attribute if the compiler is GNU C.
+Expands to the GNU C <literal>format</literal> function attribute if the compiler is <command>gcc</command>.
 This is used for declaring functions which take a variable number of
 arguments, with the same syntax as <function>printf()</function>.
 It allows the compiler to type-check the arguments passed to the function.
@@ -160,7 +184,7 @@ gint g_snprintf (gchar  *string,
 
 <!-- ##### MACRO G_GNUC_SCANF ##### -->
 <para>
-Expands to the GNU C format function attribute if the compiler is GNU C.
+Expands to the GNU C <literal>format</literal> function attribute if the compiler is <command>gcc</command>.
 This is used for declaring functions which take a variable number of
 arguments, with the same syntax as <function>scanf()</function>.
 It allows the compiler to type-check the arguments passed to the function.
@@ -174,8 +198,8 @@ See the GNU C documentation for details.
 
 <!-- ##### MACRO G_GNUC_FORMAT ##### -->
 <para>
-Expands to the GNU C format_arg function attribute if the compiler is GNU C.
-The format_arg function attribute specifies that a function takes a format
+Expands to the GNU C <literal>format_arg</literal> function attribute if the compiler is <command>gcc</command>.
+This function attribute specifies that a function takes a format
 string for a <function>printf()</function>, <function>scanf()</function>, 
 <function>strftime()</function> or <function>strfmon()</function> style
 function and modifies it, so that the result can be passed to a 
@@ -195,7 +219,7 @@ gchar *g_dgettext (gchar *domain_name, gchar *msgid) G_GNUC_FORMAT (2);
 <!-- ##### MACRO G_GNUC_FUNCTION ##### -->
 <para>
 Expands to the GNU C <literal>__FUNCTION__</literal> variable if the 
-compiler is GNU C, or "" if it isn't. The GNU C 
+compiler is <command>gcc</command>, or "" if it isn't. The GNU C 
 <literal>__FUNCTION__</literal> variable contains the name of the 
 current function. See the GNU C documentation for details. 
 </para>
@@ -205,7 +229,7 @@ current function. See the GNU C documentation for details.
 <!-- ##### MACRO G_GNUC_PRETTY_FUNCTION ##### -->
 <para>
 Expands to the GNU C <literal>__PRETTY_FUNCTION__</literal> variable 
-if the compiler is GNU C, or "" if it isn't.
+if the compiler is <command>gcc</command>, or "" if it isn't.
 The GNU C <literal>__PRETTY_FUNCTION__</literal> variable contains the 
 name of the current function. For a C program this is the same as the 
 <literal>__FUNCTION__</literal> variable but for C++ it also includes 
@@ -217,8 +241,9 @@ GNU C documentation for details.
 
 <!-- ##### MACRO G_GNUC_NO_INSTRUMENT ##### -->
 <para>
-Expands to the GNU C no_instrument_function function attribute if 
-the compiler is GNU C. Functions with this attribute will not be 
+Expands to the GNU C <literal>no_instrument_function</literal> function 
+attribute if the compiler is <command>gcc</command>. Functions with this 
+attribute will not be 
 instrumented for profiling, when the compiler is called with the
 <option>-finstrument-functions</option> option.
 See the GNU C documentation for details. 
@@ -226,6 +251,34 @@ See the GNU C documentation for details.
 
 
 
+<!-- ##### MACRO G_LIKELY ##### -->
+<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>
+if (G_LIKELY (random () != 1))
+  g_print ("not one");
+</programlisting></informalexample>
+
+@expr: the expression
+@Since: 2.2
+
+
+<!-- ##### MACRO G_UNLIKELY ##### -->
+<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>
+if (G_UNLIKELY (random () == 1))
+  g_print ("a random one");
+</programlisting></informalexample>
+
+@expr: the expression
+@Since: 2.2
+
+
 <!-- ##### MACRO G_STRLOC ##### -->
 <para>
 Expands to a string identifying the current code position. 
@@ -233,6 +286,28 @@ Expands to a string identifying the current code position.
 
 
 
+<!-- ##### MACRO G_GINT16_MODIFIER ##### -->
+<para>
+The platform dependent length modifier for constructing printf() conversion
+specifiers for values of type #gint16. It is a string literal, but doesn't
+include the percent-sign, such that you can add precision and length
+modifiers between percent-sign and conversion specifier and append a 
+conversion specifier.
+</para>
+
+<para>
+The following example prints "0x7b";
+<informalexample>
+<programlisting>
+gint16 value = 123;
+g_print ("%#" G_GINT16_MODIFIER "x", value);
+</programlisting>
+</informalexample>
+</para>
+
+@Since: 2.4
+
+
 <!-- ##### MACRO G_GINT16_FORMAT ##### -->
 <para>
 This is the platform dependent conversion specifier for scanning and
@@ -263,6 +338,14 @@ printing values of type #guint16. See also #G_GINT16_FORMAT.
 
 
 
+<!-- ##### MACRO G_GINT32_MODIFIER ##### -->
+<para>
+The platform dependent length modifier for constructing printf() conversion
+specifiers for values of type #gint32. See also #G_GINT16_MODIFIER.
+</para>
+
+@Since: 2.4
+
 <!-- ##### MACRO G_GINT32_FORMAT ##### -->
 <para>
 This is the platform dependent conversion specifier for scanning and
@@ -279,6 +362,22 @@ printing values of type #guint32. See also #G_GINT16_FORMAT.
 
 
 
+<!-- ##### MACRO G_GINT64_MODIFIER ##### -->
+<para>
+The platform dependent length modifier for constructing printf() conversion
+specifiers for values of type #gint32. See also #G_GINT16_MODIFIER.
+</para>
+
+<note>
+<para>
+Some platforms do not support printing 64 bit integers,
+even though the types are supported. On such platforms #G_GINT64_MODIFIER
+is not defined.
+</para>
+</note>
+
+@Since: 2.4
+
 <!-- ##### MACRO G_GINT64_FORMAT ##### -->
 <para>
 This is the platform dependent conversion specifier for scanning and
@@ -289,7 +388,9 @@ printing values of type #gint64. See also #G_GINT16_FORMAT.
 <para>
 Some platforms do not support scanning and printing 64 bit integers,
 even though the types are supported. On such platforms #G_GINT64_FORMAT
-is not defined.
+is not defined. Note that scanf() may not support 64 bit integers, even
+if #G_GINT64_FORMAT is defined. Due to its weak error handling, scanf() is not 
+recommended for parsing anyway; consider using g_strtoull() instead.
 </para>
 </note>
 
@@ -305,7 +406,9 @@ printing values of type #guint64. See also #G_GINT16_FORMAT.
 <para>
 Some platforms do not support scanning and printing 64 bit integers,
 even though the types are supported. On such platforms #G_GUINT64_FORMAT
-is not defined.
+is not defined.  Note that scanf() may not support 64 bit integers, even
+if #G_GINT64_FORMAT is defined. Due to its weak error handling, scanf() is not 
+recommended for parsing anyway; consider using g_strtoull() instead.
 </para>
 </note>