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 <!-- ##### SECTION Stability_Level ##### -->
21 <!-- ##### MACRO G_INLINE_FUNC ##### -->
23 This macro is used to export function prototypes so they can be linked
24 with an external version when no inlining is performed. The file which
25 implements the functions should define %G_IMPLEMENTS_INLINES
26 before including the headers which contain %G_INLINE_FUNC declarations.
27 Since inlining is very compiler-dependent using these macros correctly
28 is very difficult. Their use is strongly discouraged.
31 This macro is often mistaken for a replacement for the inline keyword;
32 inline is already declared in a portable manner in the glib headers
33 and can be used normally.
38 <!-- ##### MACRO G_STMT_START ##### -->
40 Used within multi-statement macros so that they can be used in places where
41 only one statement is expected by the compiler.
46 <!-- ##### MACRO G_STMT_END ##### -->
48 Used within multi-statement macros so that they can be used in places where
49 only one statement is expected by the compiler.
54 <!-- ##### MACRO G_BEGIN_DECLS ##### -->
56 Used (along with #G_END_DECLS) to bracket header files. If the
57 compiler in use is a C++ compiler, adds <literal>extern "C"</literal>
63 <!-- ##### MACRO G_END_DECLS ##### -->
65 Used (along with #G_BEGIN_DECLS) to bracket header files. If the
66 compiler in use is a C++ compiler, adds <literal>extern "C"</literal>
72 <!-- ##### MACRO G_N_ELEMENTS ##### -->
74 Determines the number of elements in an array. The array must be
75 declared so the compiler knows its size at compile-time; this
76 macro will not work on an array allocated on the heap, only static
77 arrays or arrays on the stack.
83 <!-- ##### MACRO G_VA_COPY ##### -->
85 Portable way to copy <type>va_list</type> variables.
88 In order to use this function, you must include <filename>string.h</filename>
89 yourself, because this macro may use <function>memmove()</function> and GLib
90 does not include <function>string.h</function> for you.
93 @ap1: the <type>va_list</type> variable to place a copy of @ap2 in.
94 @ap2: a <type>va_list</type>.
97 <!-- ##### MACRO G_STRINGIFY ##### -->
99 Accepts a macro or a string and converts it into a string after
100 preprocessor argument expansion.
103 @macro_or_string: a macro or a string.
106 <!-- ##### MACRO G_PASTE ##### -->
108 Yields a new preprocessor pasted identifier 'identifier1identifier2'
109 from its expanded arguments 'identifier1' and 'identifier2'.
112 @identifier1: an identifier
113 @identifier2: an identifier
117 <!-- ##### MACRO G_PASTE_ARGS ##### -->
126 <!-- ##### MACRO G_STATIC_ASSERT ##### -->
128 The G_STATIC_ASSERT macro lets the programmer check a condition at compile time,
129 the condition needs to be compile time computable.
130 The macro can be used in any place where a <literal>typedef</literal> is valid.
131 The macro should only be used once per source code line.
134 @expr: a constant expression.
138 <!-- ##### MACRO G_GNUC_EXTENSION ##### -->
140 Expands to <literal>__extension__</literal> when <command>gcc</command> is
141 used as the compiler.
142 This simply tells <command>gcc</command> not to warn about the following non-standard code
143 when compiling with the <option>-pedantic</option> option.
148 <!-- ##### MACRO G_GNUC_CONST ##### -->
150 Expands to the GNU C <literal>const</literal> function attribute if the compiler is
151 <command>gcc</command>. Declaring a function as const enables better optimization of calls
152 to the function. A const function doesn't examine any values except its parameters, and has no
153 effects except its return value. See the GNU C documentation for details.
156 A function that has pointer arguments and examines the data pointed to
157 must <emphasis>not</emphasis> be declared const. Likewise, a function that
158 calls a non-const function usually must not be const. It doesn't make sense
159 for a const function to return void.
164 <!-- ##### MACRO G_GNUC_PURE ##### -->
166 Expands to the GNU C <literal>pure</literal> function attribute if the compiler is
167 <command>gcc</command>. Declaring a function as pure enables better optimization of
168 calls to the function. A pure function has no effects except its return value and the
169 return value depends only on the parameters and/or global variables.
170 See the GNU C documentation for details.
175 <!-- ##### MACRO G_GNUC_MALLOC ##### -->
177 Expands to the GNU C <literal>malloc</literal> function attribute if the
178 compiler is <command>gcc</command>. Declaring a function as malloc enables
179 better optimization of the function. A function can have the malloc attribute
180 if it returns a pointer which is guaranteed to not alias with any other pointer
181 when the function returns (in practice, this means newly allocated memory).
182 See the GNU C documentation for details.
188 <!-- ##### MACRO G_GNUC_ALLOC_SIZE ##### -->
190 Expands to the GNU C <literal>alloc_size</literal> function attribute if the
191 compiler is a new enough <command>gcc</command>. This attribute tells the
192 compiler that the function returns a pointer to memory of a size that is
193 specified by the @x<!-- -->th function parameter.
194 See the GNU C documentation for details.
197 @x: the index of the argument specifying the allocation size
201 <!-- ##### MACRO G_GNUC_ALLOC_SIZE2 ##### -->
203 Expands to the GNU C <literal>alloc_size</literal> function attribute if the
204 compiler is a new enough <command>gcc</command>. This attribute tells the
205 compiler that the function returns a pointer to memory of a size that is
206 specified by the product of two function parameters.
207 See the GNU C documentation for details.
210 @x: the index of the argument specifying one factor of the allocation size
211 @y: the index of the argument specifying the second factor of the allocation size
215 <!-- ##### MACRO G_GNUC_DEPRECATED ##### -->
217 Expands to the GNU C <literal>deprecated</literal> attribute if the compiler
218 is <command>gcc</command>.
219 It can be used to mark typedefs, variables and functions as deprecated.
220 When called with the <option>-Wdeprecated-declarations</option> option, the compiler will
221 generate warnings when deprecated interfaces are used.
222 See the GNU C documentation for details.
228 <!-- ##### MACRO G_GNUC_NORETURN ##### -->
230 Expands to the GNU C <literal>noreturn</literal> function attribute if the
231 compiler is <command>gcc</command>. It is used for declaring functions which never return.
232 It enables optimization of the function, and avoids possible compiler
233 warnings. See the GNU C documentation for details.
238 <!-- ##### MACRO G_GNUC_UNUSED ##### -->
240 Expands to the GNU C <literal>unused</literal> function attribute if the compiler is
241 <command>gcc</command>. It is used for declaring functions which may never be used.
242 It avoids possible compiler warnings. See the GNU C documentation for details.
247 <!-- ##### MACRO G_GNUC_PRINTF ##### -->
249 Expands to the GNU C <literal>format</literal> function attribute if the compiler is
250 <command>gcc</command>. This is used for declaring functions which take a variable number of
251 arguments, with the same syntax as <function>printf()</function>.
252 It allows the compiler to type-check the arguments passed to the function.
253 See the GNU C documentation for details.
255 <informalexample><programlisting>
256 gint g_snprintf (gchar *string,
259 ...) G_GNUC_PRINTF (3, 4);
260 </programlisting></informalexample>
262 @format_idx: the index of the argument corresponding to the format string.
263 (The arguments are numbered from 1).
264 @arg_idx: the index of the first of the format arguments.
267 <!-- ##### MACRO G_GNUC_SCANF ##### -->
269 Expands to the GNU C <literal>format</literal> function attribute if the compiler is <command>gcc</command>.
270 This is used for declaring functions which take a variable number of
271 arguments, with the same syntax as <function>scanf()</function>.
272 It allows the compiler to type-check the arguments passed to the function.
273 See the GNU C documentation for details.
276 @format_idx: the index of the argument corresponding to the format string.
277 (The arguments are numbered from 1).
278 @arg_idx: the index of the first of the format arguments.
281 <!-- ##### MACRO G_GNUC_FORMAT ##### -->
283 Expands to the GNU C <literal>format_arg</literal> function attribute if the compiler is <command>gcc</command>.
284 This function attribute specifies that a function takes a format
285 string for a <function>printf()</function>, <function>scanf()</function>,
286 <function>strftime()</function> or <function>strfmon()</function> style
287 function and modifies it, so that the result can be passed to a
288 <function>printf()</function>, <function>scanf()</function>,
289 <function>strftime()</function> or <function>strfmon()</function> style
290 function (with the remaining arguments to the format function the same as
291 they would have been for the unmodified string).
292 See the GNU C documentation for details.
294 <informalexample><programlisting>
295 gchar *g_dgettext (gchar *domain_name, gchar *msgid) G_GNUC_FORMAT (2);
296 </programlisting></informalexample>
298 @arg_idx: the index of the argument.
301 <!-- ##### MACRO G_GNUC_NULL_TERMINATED ##### -->
303 Expands to the GNU C <literal>sentinel</literal> function attribute if the
304 compiler is <command>gcc</command>, or "" if it isn't. This function attribute
305 only applies to variadic functions and instructs the compiler to check that
306 the argument list is terminated with an explicit %NULL.
307 See the GNU C documentation for details.
314 <!-- ##### MACRO G_GNUC_WARN_UNUSED_RESULT ##### -->
316 Expands to the GNU C <literal>warn_unused_result</literal> function attribute
317 if the compiler is <command>gcc</command>, or "" if it isn't. This function
318 attribute makes the compiler emit a warning if the result of a function call
319 is ignored. See the GNU C documentation for details.
325 <!-- ##### MACRO G_GNUC_FUNCTION ##### -->
327 Expands to "" on all modern compilers, and to <literal>__FUNCTION__</literal>
328 on <command>gcc</command> version 2.x. Don't use it.
331 @Deprecated: 2.16: Use #G_STRFUNC instead.
334 <!-- ##### MACRO G_GNUC_PRETTY_FUNCTION ##### -->
336 Expands to "" on all modern compilers, and to
337 <literal>__PRETTY_FUNCTION__</literal> on <command>gcc</command> version 2.x.
341 @Deprecated: 2.16: Use #G_STRFUNC instead.
344 <!-- ##### MACRO G_GNUC_NO_INSTRUMENT ##### -->
346 Expands to the GNU C <literal>no_instrument_function</literal> function
347 attribute if the compiler is <command>gcc</command>. Functions with this
348 attribute will not be
349 instrumented for profiling, when the compiler is called with the
350 <option>-finstrument-functions</option> option.
351 See the GNU C documentation for details.
356 <!-- ##### MACRO G_HAVE_GNUC_VISIBILITY ##### -->
363 <!-- ##### MACRO G_GNUC_INTERNAL ##### -->
365 This attribute can be used for marking library functions as being used
366 internally to the library only, which may allow the compiler to handle
367 function calls more efficiently.
368 Note that static functions do not need to be marked as internal in this way.
369 See the GNU C documentation for details.
372 When using a compiler that supports the GNU C hidden visibility attribute,
373 this macro expands to <literal>__attribute__((visibility("hidden")))</literal>.
374 When using the Sun Studio compiler, it expands to <literal>__hidden</literal>.
377 Note that for portability, the attribute should be placed before the
378 function declaration. While GCC allows the macro after the declaration,
381 <informalexample><programlisting>
383 void _g_log_fallback_handler (const gchar *log_domain,
384 GLogLevelFlags log_level,
385 const gchar *message,
386 gpointer unused_data);
387 </programlisting></informalexample>
393 <!-- ##### MACRO G_GNUC_MAY_ALIAS ##### -->
395 Expands to the GNU C <literal>may_alias</literal> type attribute
396 if the compiler is <command>gcc</command>. Types with this attribute
397 will not be subjected to type-based alias analysis, but are assumed
398 to alias with any other type, just like char.
399 See the GNU C documentation for details.
406 <!-- ##### MACRO G_LIKELY ##### -->
408 Hints the compiler that the expression is likely to evaluate to a true
409 value. The compiler may use this information for optimizations.
411 <informalexample><programlisting>
412 if (G_LIKELY (random () != 1))
414 </programlisting></informalexample>
416 @expr: the expression
417 @Returns: the value of @expr
421 <!-- ##### MACRO G_UNLIKELY ##### -->
423 Hints the compiler that the expression is unlikely to evaluate to a true
424 value. The compiler may use this information for optimizations.
426 <informalexample><programlisting>
427 if (G_UNLIKELY (random () == 1))
428 g_print ("a random one");
429 </programlisting></informalexample>
431 @expr: the expression
432 @Returns: the value of @expr
436 <!-- ##### MACRO G_STRLOC ##### -->
438 Expands to a string identifying the current code position.
443 <!-- ##### MACRO G_STRFUNC ##### -->
445 Expands to a string identifying the current function.
451 <!-- ##### MACRO G_GINT16_MODIFIER ##### -->
453 The platform dependent length modifier for conversion specifiers for scanning
454 and printing values of type #gint16 or #guint16. It is a string literal,
455 but doesn't include the percent-sign, such that you can add precision and
456 length modifiers between percent-sign and conversion specifier and append a
457 conversion specifier.
461 The following example prints "0x7b";
465 g_print ("%#" G_GINT16_MODIFIER "x", value);
473 <!-- ##### MACRO G_GINT16_FORMAT ##### -->
475 This is the platform dependent conversion specifier for scanning and
476 printing values of type #gint16. It is a string literal, but doesn't
477 include the percent-sign, such that you can add precision and length
478 modifiers between percent-sign and conversion specifier.
486 sscanf ("42", "%" G_GINT16_FORMAT, &in)
488 g_print ("%" G_GINT32_FORMAT, out);
495 <!-- ##### MACRO G_GUINT16_FORMAT ##### -->
497 This is the platform dependent conversion specifier for scanning and
498 printing values of type #guint16. See also #G_GINT16_FORMAT.
503 <!-- ##### MACRO G_GINT32_MODIFIER ##### -->
505 The platform dependent length modifier for conversion specifiers for scanning
506 and printing values of type #gint32 or #guint32. It is a string literal,
507 See also #G_GINT16_MODIFIER.
513 <!-- ##### MACRO G_GINT32_FORMAT ##### -->
515 This is the platform dependent conversion specifier for scanning and
516 printing values of type #gint32. See also #G_GINT16_FORMAT.
521 <!-- ##### MACRO G_GUINT32_FORMAT ##### -->
523 This is the platform dependent conversion specifier for scanning and
524 printing values of type #guint32. See also #G_GINT16_FORMAT.
529 <!-- ##### MACRO G_GINT64_MODIFIER ##### -->
531 The platform dependent length modifier for conversion specifiers for scanning
532 and printing values of type #gint64 or #guint64. It is a string literal.
537 Some platforms do not support printing 64 bit integers,
538 even though the types are supported. On such platforms #G_GINT64_MODIFIER
546 <!-- ##### MACRO G_GINT64_FORMAT ##### -->
548 This is the platform dependent conversion specifier for scanning and
549 printing values of type #gint64. See also #G_GINT16_FORMAT.
554 Some platforms do not support scanning and printing 64 bit integers,
555 even though the types are supported. On such platforms #G_GINT64_FORMAT
556 is not defined. Note that scanf() may not support 64 bit integers, even
557 if #G_GINT64_FORMAT is defined. Due to its weak error handling, scanf()
558 is not recommended for parsing anyway; consider using g_ascii_strtoull()
565 <!-- ##### MACRO G_GUINT64_FORMAT ##### -->
567 This is the platform dependent conversion specifier for scanning and
568 printing values of type #guint64. See also #G_GINT16_FORMAT.
573 Some platforms do not support scanning and printing 64 bit integers,
574 even though the types are supported. On such platforms #G_GUINT64_FORMAT
575 is not defined. Note that scanf() may not support 64 bit integers, even
576 if #G_GINT64_FORMAT is defined. Due to its weak error handling, scanf() is not
577 recommended for parsing anyway; consider using g_strtoull() instead.
583 <!-- ##### MACRO G_GSIZE_MODIFIER ##### -->
585 The platform dependent length modifier for conversion specifiers for scanning
586 and printing values of type #gsize or #gssize. It is a string literal,
592 <!-- ##### MACRO G_GSIZE_FORMAT ##### -->
594 This is the platform dependent conversion specifier for scanning and
595 printing values of type #gsize. See also #G_GINT16_FORMAT.
601 <!-- ##### MACRO G_GSSIZE_FORMAT ##### -->
603 This is the platform dependent conversion specifier for scanning and
604 printing values of type #gssize. See also #G_GINT16_FORMAT.
610 <!-- ##### MACRO G_GOFFSET_MODIFIER ##### -->
612 The platform dependent length modifier for conversion specifiers for scanning
613 and printing values of type #goffset. It is a string literal. See also
620 <!-- ##### MACRO G_GOFFSET_FORMAT ##### -->
622 This is the platform dependent conversion specifier for scanning and
623 printing values of type #goffset. See also #G_GINT64_FORMAT.
630 <!-- ##### MACRO G_GINTPTR_MODIFIER ##### -->
632 The platform dependent length modifier for conversion specifiers for scanning
633 and printing values of type #gintptr or #guintptr. It is a string literal.
639 <!-- ##### MACRO G_GINTPTR_FORMAT ##### -->
641 This is the platform dependent conversion specifier for scanning and
642 printing values of type #gintptr.
648 <!-- ##### MACRO G_GUINTPTR_FORMAT ##### -->
650 This is the platform dependent conversion specifier for scanning and
651 printing values of type #guintptr.