1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 specialized macros which are not used often.
7 <!-- ##### SECTION Long_Description ##### -->
9 These macros provide more specialized features which are not needed so often
10 by application programmers.
13 <!-- ##### SECTION See_Also ##### -->
18 <!-- ##### MACRO G_INLINE_FUNC ##### -->
20 Used to declare inline functions. If inline functions are not supported on
21 the particular platform, the macro evaluates to the empty string.
26 <!-- ##### MACRO G_STMT_START ##### -->
28 Used within multi-statement macros so that they can be used in places where
29 only one statement is expected by the compiler.
34 <!-- ##### MACRO G_STMT_END ##### -->
36 Used within multi-statement macros so that they can be used in places where
37 only one statement is expected by the compiler.
42 <!-- ##### MACRO G_BEGIN_DECLS ##### -->
44 Used (along with #G_END_DECLS) to bracket header files. If the
45 compiler in use is a C++ compiler, adds <literal>extern "C"</literal>
51 <!-- ##### MACRO G_END_DECLS ##### -->
53 Used (along with #G_BEGIN_DECLS) to bracket header files. If the
54 compiler in use is a C++ compiler, adds <literal>extern "C"</literal>
60 <!-- ##### MACRO G_N_ELEMENTS ##### -->
62 Determines the number of elements in an array. The array must be
63 declared so the compiler knows its size at compile-time; this
64 macro will not work on an array allocated on the heap, only static
65 arrays or arrays on the stack.
71 <!-- ##### MACRO G_VA_COPY ##### -->
73 Portable way to copy <type>va_list</type> variables.
76 In order to use this function, you must include <filename>string.h</filename>
77 yourself, because this macro may use <function>memmove()</function> and GLib
78 does not include <function>string.h</function> for you.
81 <!-- # Unused Parameters # -->
82 @ap1: the <type>va_list</type> variable to place a copy of @ap2 in.
83 @ap2: a <type>va_list</type>.
86 <!-- ##### MACRO G_STRINGIFY ##### -->
88 Accepts a macro or a string and converts it into a string.
91 @macro_or_string: a macro or a string.
94 <!-- ##### MACRO G_GNUC_EXTENSION ##### -->
96 Expands to <literal>__extension__</literal> when <command>gcc</command> is
98 This simply tells <command>gcc</command> not to warn about the following non-standard code
99 when compiling with the <option>-pedantic</option> option.
104 <!-- ##### MACRO G_GNUC_CONST ##### -->
106 Expands to the GNU C <literal>const</literal> function attribute if the compiler is
107 <command>gcc</command>. Declaring a function as const enables better optimization of calls
108 to the function. A const function doesn't examine any values except its parameters, and has no
109 effects except its return value. See the GNU C documentation for details.
112 A function that has pointer arguments and examines the data pointed to
113 must <emphasis>not</emphasis> be declared const. Likewise, a function that
114 calls a non-const function usually must not be const. It doesn't make sense
115 for a const function to return void.
120 <!-- ##### MACRO G_GNUC_PURE ##### -->
122 Expands to the GNU C <literal>pure</literal> function attribute if the compiler is
123 <command>gcc</command>. Declaring a function as pure enables better optimization of
124 calls to the function. A pure function has no effects except its return value and the
125 return value depends only on the parameters and/or global variables.
126 See the GNU C documentation for details.
131 <!-- ##### MACRO G_GNUC_MALLOC ##### -->
133 Expands to the GNU C <literal>malloc</literal> function attribute if the compiler is
134 <command>gcc</command>. Declaring a function as malloc enables better optimization of the
135 function. A function can have the malloc attribute if it returns a pointer which is guaranteed
136 to not alias with any other pointer when the function returns (in practice, this means newly
138 See the GNU C documentation for details.
144 <!-- ##### MACRO G_GNUC_DEPRECATED ##### -->
146 Expands to the GNU C <literal>deprecated</literal> attribute if the compiler
147 is <command>gcc</command>.
148 It can be used to mark typedefs, variables and functions as deprecated.
149 When called with the <option>-Wdeprecated</option> option, the compiler will
150 generate warnings when deprecated interfaces are used.
151 See the GNU C documentation for details.
157 <!-- ##### MACRO G_GNUC_NORETURN ##### -->
159 Expands to the GNU C <literal>noreturn</literal> function attribute if the
160 compiler is <command>gcc</command>. It is used for declaring functions which never return.
161 It enables optimization of the function, and avoids possible compiler
162 warnings. See the GNU C documentation for details.
167 <!-- ##### MACRO G_GNUC_UNUSED ##### -->
169 Expands to the GNU C <literal>unused</literal> function attribute if the compiler is
170 <command>gcc</command>. It is used for declaring functions which may never be used.
171 It avoids possible compiler warnings. See the GNU C documentation for details.
176 <!-- ##### MACRO G_GNUC_PRINTF ##### -->
178 Expands to the GNU C <literal>format</literal> function attribute if the compiler is
179 <command>gcc</command>. This is used for declaring functions which take a variable number of
180 arguments, with the same syntax as <function>printf()</function>.
181 It allows the compiler to type-check the arguments passed to the function.
182 See the GNU C documentation for details.
184 <informalexample><programlisting>
185 gint g_snprintf (gchar *string,
188 ...) G_GNUC_PRINTF (3, 4);
189 </programlisting></informalexample>
191 @format_idx: the index of the argument corresponding to the format string.
192 (The arguments are numbered from 1).
193 @arg_idx: the index of the first of the format arguments.
196 <!-- ##### MACRO G_GNUC_SCANF ##### -->
198 Expands to the GNU C <literal>format</literal> function attribute if the compiler is <command>gcc</command>.
199 This is used for declaring functions which take a variable number of
200 arguments, with the same syntax as <function>scanf()</function>.
201 It allows the compiler to type-check the arguments passed to the function.
202 See the GNU C documentation for details.
205 @format_idx: the index of the argument corresponding to the format string.
206 (The arguments are numbered from 1).
207 @arg_idx: the index of the first of the format arguments.
210 <!-- ##### MACRO G_GNUC_FORMAT ##### -->
212 Expands to the GNU C <literal>format_arg</literal> function attribute if the compiler is <command>gcc</command>.
213 This function attribute specifies that a function takes a format
214 string for a <function>printf()</function>, <function>scanf()</function>,
215 <function>strftime()</function> or <function>strfmon()</function> style
216 function and modifies it, so that the result can be passed to a
217 <function>printf()</function>, <function>scanf()</function>,
218 <function>strftime()</function> or <function>strfmon()</function> style
219 function (with the remaining arguments to the format function the same as
220 they would have been for the unmodified string).
221 See the GNU C documentation for details.
223 <informalexample><programlisting>
224 gchar *g_dgettext (gchar *domain_name, gchar *msgid) G_GNUC_FORMAT (2);
225 </programlisting></informalexample>
227 @arg_idx: the index of the argument.
230 <!-- ##### MACRO G_GNUC_NULL_TERMINATED ##### -->
232 Expands to the GNU C <literal>sentinel</literal> function attribute if the
233 compiler is <command>gcc</command>, or "" if it isn't. This function attribute
234 only applies to variadic functions and instructs the compiler to check that
235 the argument list is terminated with an explicit %NULL.
236 See the GNU C documentation for details.
241 <!-- ##### MACRO G_GNUC_FUNCTION ##### -->
243 Expands to the GNU C <literal>__FUNCTION__</literal> variable if the
244 compiler is <command>gcc</command>, or "" if it isn't. The GNU C
245 <literal>__FUNCTION__</literal> variable contains the name of the
246 current function. See the GNU C documentation for details.
251 <!-- ##### MACRO G_GNUC_PRETTY_FUNCTION ##### -->
253 Expands to the GNU C <literal>__PRETTY_FUNCTION__</literal> variable
254 if the compiler is <command>gcc</command>, or "" if it isn't.
255 The GNU C <literal>__PRETTY_FUNCTION__</literal> variable contains the
256 name of the current function. For a C program this is the same as the
257 <literal>__FUNCTION__</literal> variable but for C++ it also includes
258 extra information such as the class and function prototype. See the
259 GNU C documentation for details.
264 <!-- ##### MACRO G_GNUC_NO_INSTRUMENT ##### -->
266 Expands to the GNU C <literal>no_instrument_function</literal> function
267 attribute if the compiler is <command>gcc</command>. Functions with this
268 attribute will not be
269 instrumented for profiling, when the compiler is called with the
270 <option>-finstrument-functions</option> option.
271 See the GNU C documentation for details.
276 <!-- ##### MACRO G_HAVE_GNUC_VISIBILITY ##### -->
278 This macro is defined as 1 if the the compiler supports ELF visibility
279 attributes (currently only <command>gcc</command>).
286 <!-- ##### MACRO G_GNUC_INTERNAL ##### -->
288 Expands to the GNU C <literal>visibility(hidden)</literal> attribute if the
289 compiler supports it (currently only <command>gcc</command>). This attribute
290 can be used for marking library functions as being used internally to the lib
291 only, to not create inefficient PLT entries. Note that static functions do not
292 need to be marked as internal in this way. See the GNU C documentation for details.
299 <!-- ##### MACRO G_LIKELY ##### -->
301 Hints the compiler that the expression is likely to evaluate to a true
302 value. The compiler may use this information for optimizations.
304 <informalexample><programlisting>
305 if (G_LIKELY (random () != 1))
307 </programlisting></informalexample>
309 @expr: the expression
313 <!-- ##### MACRO G_UNLIKELY ##### -->
315 Hints the compiler that the expression is unlikely to evaluate to a true
316 value. The compiler may use this information for optimizations.
318 <informalexample><programlisting>
319 if (G_UNLIKELY (random () == 1))
320 g_print ("a random one");
321 </programlisting></informalexample>
323 @expr: the expression
327 <!-- ##### MACRO G_STRLOC ##### -->
329 Expands to a string identifying the current code position.
334 <!-- ##### MACRO G_STRFUNC ##### -->
336 Expands to a string identifying the current function.
342 <!-- ##### MACRO G_GINT16_MODIFIER ##### -->
344 The platform dependent length modifier for constructing printf() conversion
345 specifiers for values of type #gint16 or #guint16. It is a string literal,
346 but doesn't include the percent-sign, such that you can add precision and
347 length modifiers between percent-sign and conversion specifier and append a
348 conversion specifier.
352 The following example prints "0x7b";
356 g_print ("%#" G_GINT16_MODIFIER "x", value);
364 <!-- ##### MACRO G_GINT16_FORMAT ##### -->
366 This is the platform dependent conversion specifier for scanning and
367 printing values of type #gint16. It is a string literal, but doesn't
368 include the percent-sign, such that you can add precision and length
369 modifiers between percent-sign and conversion specifier.
377 sscanf ("42", "%" G_GINT16_FORMAT, &in)
379 g_print ("%" G_GINT32_FORMAT, out);
386 <!-- ##### MACRO G_GUINT16_FORMAT ##### -->
388 This is the platform dependent conversion specifier for scanning and
389 printing values of type #guint16. See also #G_GINT16_FORMAT.
394 <!-- ##### MACRO G_GINT32_MODIFIER ##### -->
396 The platform dependent length modifier for constructing printf() conversion
397 specifiers for values of type #gint32 or #guint32. See also #G_GINT16_MODIFIER.
403 <!-- ##### MACRO G_GINT32_FORMAT ##### -->
405 This is the platform dependent conversion specifier for scanning and
406 printing values of type #gint32. See also #G_GINT16_FORMAT.
411 <!-- ##### MACRO G_GUINT32_FORMAT ##### -->
413 This is the platform dependent conversion specifier for scanning and
414 printing values of type #guint32. See also #G_GINT16_FORMAT.
419 <!-- ##### MACRO G_GINT64_MODIFIER ##### -->
421 The platform dependent length modifier for constructing printf() conversion
422 specifiers for values of type #gint64 or #guint64. See also #G_GINT16_MODIFIER.
427 Some platforms do not support printing 64 bit integers,
428 even though the types are supported. On such platforms #G_GINT64_MODIFIER
436 <!-- ##### MACRO G_GINT64_FORMAT ##### -->
438 This is the platform dependent conversion specifier for scanning and
439 printing values of type #gint64. See also #G_GINT16_FORMAT.
444 Some platforms do not support scanning and printing 64 bit integers,
445 even though the types are supported. On such platforms #G_GINT64_FORMAT
446 is not defined. Note that scanf() may not support 64 bit integers, even
447 if #G_GINT64_FORMAT is defined. Due to its weak error handling, scanf() is not
448 recommended for parsing anyway; consider using g_strtoull() instead.
454 <!-- ##### MACRO G_GUINT64_FORMAT ##### -->
456 This is the platform dependent conversion specifier for scanning and
457 printing values of type #guint64. See also #G_GINT16_FORMAT.
462 Some platforms do not support scanning and printing 64 bit integers,
463 even though the types are supported. On such platforms #G_GUINT64_FORMAT
464 is not defined. Note that scanf() may not support 64 bit integers, even
465 if #G_GINT64_FORMAT is defined. Due to its weak error handling, scanf() is not
466 recommended for parsing anyway; consider using g_strtoull() instead.
472 <!-- ##### MACRO G_GSIZE_MODIFIER ##### -->
474 The platform dependent length modifier for constructing printf() conversion
475 specifiers for values of type #gsize or #gssize. See also #G_GINT16_MODIFIER.
481 <!-- ##### MACRO G_GSIZE_FORMAT ##### -->
483 This is the platform dependent conversion specifier for scanning and
484 printing values of type #gsize. See also #G_GINT16_FORMAT.
490 <!-- ##### MACRO G_GSSIZE_FORMAT ##### -->
492 This is the platform dependent conversion specifier for scanning and
493 printing values of type #gssize. See also #G_GINT16_FORMAT.