Update to version 2.33.1
[profile/ivi/glib2.git] / docs / reference / glib / html / glib-Miscellaneous-Macros.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>Miscellaneous Macros</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
7 <link rel="home" href="index.html" title="GLib Reference Manual">
8 <link rel="up" href="glib-fundamentals.html" title="GLib Fundamentals">
9 <link rel="prev" href="glib-Numerical-Definitions.html" title="Numerical Definitions">
10 <link rel="next" href="glib-Atomic-Operations.html" title="Atomic Operations">
11 <meta name="generator" content="GTK-Doc V1.18 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
13 </head>
14 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
16 <tr valign="middle">
17 <td><a accesskey="p" href="glib-Numerical-Definitions.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
18 <td><a accesskey="u" href="glib-fundamentals.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
19 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
20 <th width="100%" align="center">GLib Reference Manual</th>
21 <td><a accesskey="n" href="glib-Atomic-Operations.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
22 </tr>
23 <tr><td colspan="5" class="shortcuts">
24 <a href="#glib-Miscellaneous-Macros.synopsis" class="shortcut">Top</a>
25                    | 
26                   <a href="#glib-Miscellaneous-Macros.description" class="shortcut">Description</a>
27 </td></tr>
28 </table>
29 <div class="refentry">
30 <a name="glib-Miscellaneous-Macros"></a><div class="titlepage"></div>
31 <div class="refnamediv"><table width="100%"><tr>
32 <td valign="top">
33 <h2><span class="refentrytitle"><a name="glib-Miscellaneous-Macros.top_of_page"></a>Miscellaneous Macros</span></h2>
34 <p>Miscellaneous Macros — specialized macros which are not used often</p>
35 </td>
36 <td valign="top" align="right"></td>
37 </tr></table></div>
38 <div class="refsynopsisdiv">
39 <a name="glib-Miscellaneous-Macros.synopsis"></a><h2>Synopsis</h2>
40 <pre class="synopsis">
41 #include &lt;glib.h&gt;
42
43 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-INLINE-FUNC:CAPS" title="G_INLINE_FUNC">G_INLINE_FUNC</a>
44
45 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-STMT-START:CAPS" title="G_STMT_START">G_STMT_START</a>
46 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-STMT-END:CAPS" title="G_STMT_END">G_STMT_END</a>
47
48 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-BEGIN-DECLS:CAPS" title="G_BEGIN_DECLS">G_BEGIN_DECLS</a>
49 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-END-DECLS:CAPS" title="G_END_DECLS">G_END_DECLS</a>
50
51 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-VA-COPY:CAPS" title="G_VA_COPY()">G_VA_COPY</a>                           (ap1,
52                                                          ap2)
53
54 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-STRINGIFY:CAPS" title="G_STRINGIFY()">G_STRINGIFY</a>                         (macro_or_string)
55 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-PASTE:CAPS" title="G_PASTE()">G_PASTE</a>                             (identifier1,
56                                                          identifier2)
57 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-STATIC-ASSERT:CAPS" title="G_STATIC_ASSERT()">G_STATIC_ASSERT</a>                     (expr)
58 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-STATIC-ASSERT-EXPR:CAPS" title="G_STATIC_ASSERT_EXPR()">G_STATIC_ASSERT_EXPR</a>                (expr)
59
60 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-EXTENSION:CAPS" title="G_GNUC_EXTENSION">G_GNUC_EXTENSION</a>
61 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-CONST:CAPS" title="G_GNUC_CONST">G_GNUC_CONST</a>
62 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-PURE:CAPS" title="G_GNUC_PURE">G_GNUC_PURE</a>
63 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-MALLOC:CAPS" title="G_GNUC_MALLOC">G_GNUC_MALLOC</a>
64 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-ALLOC-SIZE:CAPS" title="G_GNUC_ALLOC_SIZE()">G_GNUC_ALLOC_SIZE</a>                   (x)
65 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-ALLOC-SIZE2:CAPS" title="G_GNUC_ALLOC_SIZE2()">G_GNUC_ALLOC_SIZE2</a>                  (x,
66                                                          y)
67 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-DEPRECATED:CAPS" title="G_GNUC_DEPRECATED">G_GNUC_DEPRECATED</a>
68 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-DEPRECATED-FOR:CAPS" title="G_GNUC_DEPRECATED_FOR()">G_GNUC_DEPRECATED_FOR</a>               (f)
69 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-BEGIN-IGNORE-DEPRECATIONS:CAPS" title="G_GNUC_BEGIN_IGNORE_DEPRECATIONS">G_GNUC_BEGIN_IGNORE_DEPRECATIONS</a>
70 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-END-IGNORE-DEPRECATIONS:CAPS" title="G_GNUC_END_IGNORE_DEPRECATIONS">G_GNUC_END_IGNORE_DEPRECATIONS</a>
71 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-NORETURN:CAPS" title="G_GNUC_NORETURN">G_GNUC_NORETURN</a>
72 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-UNUSED:CAPS" title="G_GNUC_UNUSED">G_GNUC_UNUSED</a>
73 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-PRINTF:CAPS" title="G_GNUC_PRINTF()">G_GNUC_PRINTF</a>                       (format_idx,
74                                                          arg_idx)
75 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-SCANF:CAPS" title="G_GNUC_SCANF()">G_GNUC_SCANF</a>                        (format_idx,
76                                                          arg_idx)
77 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-FORMAT:CAPS" title="G_GNUC_FORMAT()">G_GNUC_FORMAT</a>                       (arg_idx)
78 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-NULL-TERMINATED:CAPS" title="G_GNUC_NULL_TERMINATED">G_GNUC_NULL_TERMINATED</a>
79 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-WARN-UNUSED-RESULT:CAPS" title="G_GNUC_WARN_UNUSED_RESULT">G_GNUC_WARN_UNUSED_RESULT</a>
80 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-FUNCTION:CAPS" title="G_GNUC_FUNCTION">G_GNUC_FUNCTION</a>
81 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-PRETTY-FUNCTION:CAPS" title="G_GNUC_PRETTY_FUNCTION">G_GNUC_PRETTY_FUNCTION</a>
82 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-NO-INSTRUMENT:CAPS" title="G_GNUC_NO_INSTRUMENT">G_GNUC_NO_INSTRUMENT</a>
83 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-HAVE-GNUC-VISIBILITY:CAPS" title="G_HAVE_GNUC_VISIBILITY">G_HAVE_GNUC_VISIBILITY</a>
84 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-INTERNAL:CAPS" title="G_GNUC_INTERNAL">G_GNUC_INTERNAL</a>
85 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-MAY-ALIAS:CAPS" title="G_GNUC_MAY_ALIAS">G_GNUC_MAY_ALIAS</a>
86
87 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-DEPRECATED:CAPS" title="G_DEPRECATED">G_DEPRECATED</a>
88 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-DEPRECATED-FOR:CAPS" title="G_DEPRECATED_FOR()">G_DEPRECATED_FOR</a>                    (f)
89 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-UNAVAILABLE:CAPS" title="G_UNAVAILABLE()">G_UNAVAILABLE</a>                       (maj,
90                                                          min)
91
92 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-LIKELY:CAPS" title="G_LIKELY()">G_LIKELY</a>                            (expr)
93 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-UNLIKELY:CAPS" title="G_UNLIKELY()">G_UNLIKELY</a>                          (expr)
94
95 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-STRLOC:CAPS" title="G_STRLOC">G_STRLOC</a>
96 #define             <a class="link" href="glib-Miscellaneous-Macros.html#G-STRFUNC:CAPS" title="G_STRFUNC">G_STRFUNC</a>
97 </pre>
98 </div>
99 <div class="refsect1">
100 <a name="glib-Miscellaneous-Macros.description"></a><h2>Description</h2>
101 <p>
102 These macros provide more specialized features which are not
103 needed so often by application programmers.
104 </p>
105 </div>
106 <div class="refsect1">
107 <a name="glib-Miscellaneous-Macros.details"></a><h2>Details</h2>
108 <div class="refsect2">
109 <a name="G-INLINE-FUNC:CAPS"></a><h3>G_INLINE_FUNC</h3>
110 <pre class="programlisting">#  define G_INLINE_FUNC
111 </pre>
112 <p>
113 This macro is used to export function prototypes so they can be linked
114 with an external version when no inlining is performed. The file which
115 implements the functions should define <code class="literal">G_IMPLEMENTS_INLINES</code>
116 before including the headers which contain <a class="link" href="glib-Miscellaneous-Macros.html#G-INLINE-FUNC:CAPS" title="G_INLINE_FUNC"><code class="literal">G_INLINE_FUNC</code></a> declarations.
117 Since inlining is very compiler-dependent using these macros correctly
118 is very difficult. Their use is strongly discouraged.
119 </p>
120 <p>
121 This macro is often mistaken for a replacement for the inline keyword;
122 inline is already declared in a portable manner in the GLib headers
123 and can be used normally.
124 </p>
125 </div>
126 <hr>
127 <div class="refsect2">
128 <a name="G-STMT-START:CAPS"></a><h3>G_STMT_START</h3>
129 <pre class="programlisting">#  define G_STMT_START  do
130 </pre>
131 <p>
132 Used within multi-statement macros so that they can be used in places
133 where only one statement is expected by the compiler.
134 </p>
135 </div>
136 <hr>
137 <div class="refsect2">
138 <a name="G-STMT-END:CAPS"></a><h3>G_STMT_END</h3>
139 <pre class="programlisting">#  define G_STMT_END    while (0)
140 </pre>
141 <p>
142 Used within multi-statement macros so that they can be used in places
143 where only one statement is expected by the compiler.
144 </p>
145 </div>
146 <hr>
147 <div class="refsect2">
148 <a name="G-BEGIN-DECLS:CAPS"></a><h3>G_BEGIN_DECLS</h3>
149 <pre class="programlisting"># define G_BEGIN_DECLS  extern "C" {
150 </pre>
151 <p>
152 Used (along with <a class="link" href="glib-Miscellaneous-Macros.html#G-END-DECLS:CAPS" title="G_END_DECLS"><span class="type">G_END_DECLS</span></a>) to bracket header files. If the
153 compiler in use is a C++ compiler, adds <code class="literal">extern "C"</code>
154 around the header.
155 </p>
156 </div>
157 <hr>
158 <div class="refsect2">
159 <a name="G-END-DECLS:CAPS"></a><h3>G_END_DECLS</h3>
160 <pre class="programlisting"># define G_END_DECLS    }
161 </pre>
162 <p>
163 Used (along with <a class="link" href="glib-Miscellaneous-Macros.html#G-BEGIN-DECLS:CAPS" title="G_BEGIN_DECLS"><span class="type">G_BEGIN_DECLS</span></a>) to bracket header files. If the
164 compiler in use is a C++ compiler, adds <code class="literal">extern "C"</code>
165 around the header.
166 </p>
167 </div>
168 <hr>
169 <div class="refsect2">
170 <a name="G-VA-COPY:CAPS"></a><h3>G_VA_COPY()</h3>
171 <pre class="programlisting">#define             G_VA_COPY(ap1,ap2)</pre>
172 <p>
173 Portable way to copy <span class="type">va_list</span> variables.
174 </p>
175 <p>
176 In order to use this function, you must include
177 <code class="filename">string.h</code> yourself, because this macro may
178 use <code class="function">memmove()</code> and GLib does not include <code class="filename">string.h</code>
179 for you.
180 </p>
181 <div class="variablelist"><table border="0">
182 <col align="left" valign="top">
183 <tbody>
184 <tr>
185 <td><p><span class="term"><em class="parameter"><code>ap1</code></em> :</span></p></td>
186 <td>the <span class="type">va_list</span> variable to place a copy of <em class="parameter"><code>ap2</code></em> in</td>
187 </tr>
188 <tr>
189 <td><p><span class="term"><em class="parameter"><code>ap2</code></em> :</span></p></td>
190 <td>a <span class="type">va_list</span>
191 </td>
192 </tr>
193 </tbody>
194 </table></div>
195 </div>
196 <hr>
197 <div class="refsect2">
198 <a name="G-STRINGIFY:CAPS"></a><h3>G_STRINGIFY()</h3>
199 <pre class="programlisting">#define G_STRINGIFY(macro_or_string) G_STRINGIFY_ARG (macro_or_string)
200 </pre>
201 <p>
202 Accepts a macro or a string and converts it into a string after
203 preprocessor argument expansion. For example, the following code:
204 </p>
205 <p>
206 </p>
207 <div class="informalexample"><pre class="programlisting">
208 #define AGE 27
209 const gchar *greeting = G_STRINGIFY (AGE) " today!";
210 </pre></div>
211 <p>
212 </p>
213 <p>
214 is transformed by the preprocessor into (code equivalent to):
215 </p>
216 <p>
217 </p>
218 <div class="informalexample"><pre class="programlisting">
219 const gchar *greeting = "27 today!";
220 </pre></div>
221 <p>
222 </p>
223 <div class="variablelist"><table border="0">
224 <col align="left" valign="top">
225 <tbody><tr>
226 <td><p><span class="term"><em class="parameter"><code>macro_or_string</code></em> :</span></p></td>
227 <td>a macro or a string</td>
228 </tr></tbody>
229 </table></div>
230 </div>
231 <hr>
232 <div class="refsect2">
233 <a name="G-PASTE:CAPS"></a><h3>G_PASTE()</h3>
234 <pre class="programlisting">#define G_PASTE(identifier1,identifier2)      G_PASTE_ARGS (identifier1, identifier2)
235 </pre>
236 <p>
237 Yields a new preprocessor pasted identifier
238 <code class="code">identifier1identifier2</code> from its expanded
239 arguments <em class="parameter"><code>identifier1</code></em> and <em class="parameter"><code>identifier2</code></em>. For example,
240 the following code:
241 </p>
242 <div class="informalexample"><pre class="programlisting">
243 #define GET(traveller,method) G_PASTE(traveller_get_, method) (traveller)
244 const gchar *name = GET (traveller, name);
245 const gchar *quest = GET (traveller, quest);
246 GdkColor *favourite = GET (traveller, favourite_colour);
247 </pre></div>
248 <p>
249 </p>
250 <p>
251 is transformed by the preprocessor into:
252 </p>
253 <div class="informalexample"><pre class="programlisting">
254 const gchar *name = traveller_get_name (traveller);
255 const gchar *quest = traveller_get_quest (traveller);
256 GdkColor *favourite = traveller_get_favourite_colour (traveller);
257 </pre></div>
258 <p>
259 </p>
260 <div class="variablelist"><table border="0">
261 <col align="left" valign="top">
262 <tbody>
263 <tr>
264 <td><p><span class="term"><em class="parameter"><code>identifier1</code></em> :</span></p></td>
265 <td>an identifier</td>
266 </tr>
267 <tr>
268 <td><p><span class="term"><em class="parameter"><code>identifier2</code></em> :</span></p></td>
269 <td>an identifier</td>
270 </tr>
271 </tbody>
272 </table></div>
273 <p class="since">Since 2.20</p>
274 </div>
275 <hr>
276 <div class="refsect2">
277 <a name="G-STATIC-ASSERT:CAPS"></a><h3>G_STATIC_ASSERT()</h3>
278 <pre class="programlisting">#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1]
279 </pre>
280 <p>
281 The G_STATIC_ASSERT macro lets the programmer check
282 a condition at compile time, the condition needs to
283 be compile time computable. The macro can be used in
284 any place where a <code class="literal">typedef</code> is valid.
285 </p>
286 <p>
287 </p>
288 <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
289 <h3 class="title">Note</h3>
290 <p>
291 A <code class="literal">typedef</code> is generally allowed in
292 exactly the same places that a variable declaration is
293 allowed. For this reason, you should not use
294 <code class="literal">G_STATIC_ASSERT</code> in the middle of
295 blocks of code.
296 </p>
297 </div>
298 <p>
299 </p>
300 <p>
301 The macro should only be used once per source code line.
302 </p>
303 <div class="variablelist"><table border="0">
304 <col align="left" valign="top">
305 <tbody><tr>
306 <td><p><span class="term"><em class="parameter"><code>expr</code></em> :</span></p></td>
307 <td>a constant expression</td>
308 </tr></tbody>
309 </table></div>
310 <p class="since">Since 2.20</p>
311 </div>
312 <hr>
313 <div class="refsect2">
314 <a name="G-STATIC-ASSERT-EXPR:CAPS"></a><h3>G_STATIC_ASSERT_EXPR()</h3>
315 <pre class="programlisting">#define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1 : -1]))
316 </pre>
317 <p>
318 The G_STATIC_ASSERT_EXPR macro lets the programmer check
319 a condition at compile time. The condition needs to be
320 compile time computable.
321 </p>
322 <p>
323 Unlike <code class="literal">G_STATIC_ASSERT</code>, this macro
324 evaluates to an expression and, as such, can be used in
325 the middle of other expressions. Its value should be
326 ignored. This can be accomplished by placing it as
327 the first argument of a comma expression.
328 </p>
329 <p>
330 </p>
331 <div class="informalexample"><pre class="programlisting">
332 #define ADD_ONE_TO_INT(x) \
333   (G_STATIC_ASSERT_EXPR(sizeof (x) == sizeof (int)), ((x) + 1))
334 </pre></div>
335 <p>
336 </p>
337 <div class="variablelist"><table border="0">
338 <col align="left" valign="top">
339 <tbody><tr>
340 <td><p><span class="term"><em class="parameter"><code>expr</code></em> :</span></p></td>
341 <td>a constant expression</td>
342 </tr></tbody>
343 </table></div>
344 <p class="since">Since 2.30</p>
345 </div>
346 <hr>
347 <div class="refsect2">
348 <a name="G-GNUC-EXTENSION:CAPS"></a><h3>G_GNUC_EXTENSION</h3>
349 <pre class="programlisting">#  define G_GNUC_EXTENSION __extension__
350 </pre>
351 <p>
352 Expands to <code class="literal">__extension__</code> when <span class="command"><strong>gcc</strong></span>
353 is used as the compiler. This simply tells <span class="command"><strong>gcc</strong></span> not
354 to warn about the following non-standard code when compiling with the
355 <code class="option">-pedantic</code> option.
356 </p>
357 </div>
358 <hr>
359 <div class="refsect2">
360 <a name="G-GNUC-CONST:CAPS"></a><h3>G_GNUC_CONST</h3>
361 <pre class="programlisting">#define             G_GNUC_CONST</pre>
362 <p>
363 Expands to the GNU C <code class="literal">const</code> function attribute if
364 the compiler is <span class="command"><strong>gcc</strong></span>. Declaring a function as const
365 enables better optimization of calls to the function. A const function
366 doesn't examine any values except its parameters, and has no effects
367 except its return value. See the GNU C documentation for details.
368 </p>
369 <p>
370 </p>
371 <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
372 <h3 class="title">Note</h3>
373 <p>
374 A function that has pointer arguments and examines the data pointed to
375 must <span class="emphasis"><em>not</em></span> be declared const. Likewise, a function
376 that calls a non-const function usually must not be const. It doesn't
377 make sense for a const function to return void.
378 </p>
379 </div>
380 <p>
381 </p>
382 </div>
383 <hr>
384 <div class="refsect2">
385 <a name="G-GNUC-PURE:CAPS"></a><h3>G_GNUC_PURE</h3>
386 <pre class="programlisting">#define             G_GNUC_PURE</pre>
387 <p>
388 Expands to the GNU C <code class="literal">pure</code> function attribute if the
389 compiler is <span class="command"><strong>gcc</strong></span>. Declaring a function as pure enables
390 better optimization of calls to the function. A pure function has no
391 effects except its return value and the return value depends only on
392 the parameters and/or global variables. See the GNU C documentation
393 for details.
394 </p>
395 </div>
396 <hr>
397 <div class="refsect2">
398 <a name="G-GNUC-MALLOC:CAPS"></a><h3>G_GNUC_MALLOC</h3>
399 <pre class="programlisting">#define             G_GNUC_MALLOC</pre>
400 <p>
401 Expands to the GNU C <code class="literal">malloc</code> function attribute if the
402 compiler is <span class="command"><strong>gcc</strong></span>. Declaring a function as malloc enables
403 better optimization of the function. A function can have the malloc
404 attribute if it returns a pointer which is guaranteed to not alias with
405 any other pointer when the function returns (in practice, this means newly
406 allocated memory). See the GNU C documentation for details.
407 </p>
408 <p class="since">Since 2.6</p>
409 </div>
410 <hr>
411 <div class="refsect2">
412 <a name="G-GNUC-ALLOC-SIZE:CAPS"></a><h3>G_GNUC_ALLOC_SIZE()</h3>
413 <pre class="programlisting">#define G_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
414 </pre>
415 <p>
416 Expands to the GNU C <code class="literal">alloc_size</code> function attribute
417 if the compiler is a new enough <span class="command"><strong>gcc</strong></span>. This attribute
418 tells the compiler that the function returns a pointer to memory of a
419 size that is specified by the <em class="parameter"><code>x</code></em>th function parameter.
420 See the GNU C documentation for details.
421 </p>
422 <div class="variablelist"><table border="0">
423 <col align="left" valign="top">
424 <tbody><tr>
425 <td><p><span class="term"><em class="parameter"><code>x</code></em> :</span></p></td>
426 <td>the index of the argument specifying the allocation size</td>
427 </tr></tbody>
428 </table></div>
429 <p class="since">Since 2.18</p>
430 </div>
431 <hr>
432 <div class="refsect2">
433 <a name="G-GNUC-ALLOC-SIZE2:CAPS"></a><h3>G_GNUC_ALLOC_SIZE2()</h3>
434 <pre class="programlisting">#define G_GNUC_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
435 </pre>
436 <p>
437 Expands to the GNU C <code class="literal">alloc_size</code> function attribute
438 if the compiler is a new enough <span class="command"><strong>gcc</strong></span>. This attribute
439 tells the compiler that the function returns a pointer to memory of a
440 size that is specified by the product of two function parameters.
441 See the GNU C documentation for details.
442 </p>
443 <div class="variablelist"><table border="0">
444 <col align="left" valign="top">
445 <tbody>
446 <tr>
447 <td><p><span class="term"><em class="parameter"><code>x</code></em> :</span></p></td>
448 <td>the index of the argument specifying one factor of the allocation size</td>
449 </tr>
450 <tr>
451 <td><p><span class="term"><em class="parameter"><code>y</code></em> :</span></p></td>
452 <td>the index of the argument specifying the second factor of the allocation size</td>
453 </tr>
454 </tbody>
455 </table></div>
456 <p class="since">Since 2.18</p>
457 </div>
458 <hr>
459 <div class="refsect2">
460 <a name="G-GNUC-DEPRECATED:CAPS"></a><h3>G_GNUC_DEPRECATED</h3>
461 <pre class="programlisting">#define             G_GNUC_DEPRECATED</pre>
462 <p>
463 Expands to the GNU C <code class="literal">deprecated</code> attribute if the
464 compiler is <span class="command"><strong>gcc</strong></span>. It can be used to mark typedefs,
465 variables and functions as deprecated. When called with the
466 <code class="option">-Wdeprecated-declarations</code> option, the compiler will
467 generate warnings when deprecated interfaces are used.
468 See the GNU C documentation for details.
469 </p>
470 <p class="since">Since 2.2</p>
471 </div>
472 <hr>
473 <div class="refsect2">
474 <a name="G-GNUC-DEPRECATED-FOR:CAPS"></a><h3>G_GNUC_DEPRECATED_FOR()</h3>
475 <pre class="programlisting">#define             G_GNUC_DEPRECATED_FOR(f)</pre>
476 <p>
477 Like <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-DEPRECATED:CAPS" title="G_GNUC_DEPRECATED"><code class="literal">G_GNUC_DEPRECATED</code></a>, but names the intended replacement for the
478 deprecated symbol if the version of <span class="command"><strong>gcc</strong></span> in use is
479 new enough to support custom deprecation messages.
480 See the GNU C documentation for details.
481 </p>
482 <p>
483 Note that if <em class="parameter"><code>f</code></em> is a macro, it will be expanded in the warning message.
484 You can enclose it in quotes to prevent this. (The quotes will show up
485 in the warning, but it's better than showing the macro expansion.)
486 </p>
487 <div class="variablelist"><table border="0">
488 <col align="left" valign="top">
489 <tbody><tr>
490 <td><p><span class="term"><em class="parameter"><code>f</code></em> :</span></p></td>
491 <td>the intended replacement for the deprecated symbol,
492 such as the name of a function</td>
493 </tr></tbody>
494 </table></div>
495 <p class="since">Since 2.26</p>
496 </div>
497 <hr>
498 <div class="refsect2">
499 <a name="G-GNUC-BEGIN-IGNORE-DEPRECATIONS:CAPS"></a><h3>G_GNUC_BEGIN_IGNORE_DEPRECATIONS</h3>
500 <pre class="programlisting">#define             G_GNUC_BEGIN_IGNORE_DEPRECATIONS</pre>
501 <p>
502 Tells <span class="command"><strong>gcc</strong></span> (if it is a new enough version) to
503 temporarily stop emitting warnings when functions marked with
504 <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-DEPRECATED:CAPS" title="G_GNUC_DEPRECATED"><code class="literal">G_GNUC_DEPRECATED</code></a> or <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-DEPRECATED-FOR:CAPS" title="G_GNUC_DEPRECATED_FOR()"><code class="literal">G_GNUC_DEPRECATED_FOR</code></a> are called. This is
505 useful for when you have one deprecated function calling another
506 one, or when you still have regression tests for deprecated
507 functions.
508 </p>
509 <p>
510 Use <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-END-IGNORE-DEPRECATIONS:CAPS" title="G_GNUC_END_IGNORE_DEPRECATIONS"><code class="literal">G_GNUC_END_IGNORE_DEPRECATIONS</code></a> to begin warning again. (If you
511 are not compiling with <code class="literal">-Wdeprecated-declarations</code>
512 then neither macro has any effect.)
513 </p>
514 <p>
515 This macro can be used either inside or outside of a function body,
516 but must appear on a line by itself.
517 </p>
518 <p class="since">Since 2.32</p>
519 </div>
520 <hr>
521 <div class="refsect2">
522 <a name="G-GNUC-END-IGNORE-DEPRECATIONS:CAPS"></a><h3>G_GNUC_END_IGNORE_DEPRECATIONS</h3>
523 <pre class="programlisting">#define             G_GNUC_END_IGNORE_DEPRECATIONS</pre>
524 <p>
525 Undoes the effect of <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-BEGIN-IGNORE-DEPRECATIONS:CAPS" title="G_GNUC_BEGIN_IGNORE_DEPRECATIONS"><code class="literal">G_GNUC_BEGIN_IGNORE_DEPRECATIONS</code></a>, telling
526 <span class="command"><strong>gcc</strong></span> to begin outputting warnings again
527 (assuming those warnings had been enabled to begin with).
528 </p>
529 <p>
530 This macro can be used either inside or outside of a function body,
531 but must appear on a line by itself.
532 </p>
533 <p class="since">Since 2.32</p>
534 </div>
535 <hr>
536 <div class="refsect2">
537 <a name="G-GNUC-NORETURN:CAPS"></a><h3>G_GNUC_NORETURN</h3>
538 <pre class="programlisting">#define             G_GNUC_NORETURN</pre>
539 <p>
540 Expands to the GNU C <code class="literal">noreturn</code> function attribute
541 if the compiler is <span class="command"><strong>gcc</strong></span>. It is used for declaring
542 functions which never return. It enables optimization of the function,
543 and avoids possible compiler warnings. See the GNU C documentation for
544 details.
545 </p>
546 </div>
547 <hr>
548 <div class="refsect2">
549 <a name="G-GNUC-UNUSED:CAPS"></a><h3>G_GNUC_UNUSED</h3>
550 <pre class="programlisting">#define             G_GNUC_UNUSED</pre>
551 <p>
552 Expands to the GNU C <code class="literal">unused</code> function attribute if
553 the compiler is <span class="command"><strong>gcc</strong></span>. It is used for declaring
554 functions which may never be used. It avoids possible compiler warnings.
555 See the GNU C documentation for details.
556 </p>
557 </div>
558 <hr>
559 <div class="refsect2">
560 <a name="G-GNUC-PRINTF:CAPS"></a><h3>G_GNUC_PRINTF()</h3>
561 <pre class="programlisting">#define             G_GNUC_PRINTF( format_idx, arg_idx )</pre>
562 <p>
563 Expands to the GNU C <code class="literal">format</code> function attribute
564 if the compiler is <span class="command"><strong>gcc</strong></span>. This is used for declaring
565 functions which take a variable number of arguments, with the same
566 syntax as <code class="function">printf()</code>. It allows the compiler to type-check the arguments
567 passed to the function. See the GNU C documentation for details.
568 </p>
569 <p>
570 </p>
571 <div class="informalexample"><pre class="programlisting">
572 gint g_snprintf (gchar  *string,
573                  gulong       n,
574                  gchar const *format,
575                  ...) G_GNUC_PRINTF (3, 4);
576 </pre></div>
577 <p>
578 </p>
579 <div class="variablelist"><table border="0">
580 <col align="left" valign="top">
581 <tbody>
582 <tr>
583 <td><p><span class="term"><em class="parameter"><code>format_idx</code></em> :</span></p></td>
584 <td>the index of the argument corresponding to the
585 format string (The arguments are numbered from 1)</td>
586 </tr>
587 <tr>
588 <td><p><span class="term"><em class="parameter"><code>arg_idx</code></em> :</span></p></td>
589 <td>the index of the first of the format arguments</td>
590 </tr>
591 </tbody>
592 </table></div>
593 </div>
594 <hr>
595 <div class="refsect2">
596 <a name="G-GNUC-SCANF:CAPS"></a><h3>G_GNUC_SCANF()</h3>
597 <pre class="programlisting">#define             G_GNUC_SCANF( format_idx, arg_idx )</pre>
598 <p>
599 Expands to the GNU C <code class="literal">format</code> function attribute
600 if the compiler is <span class="command"><strong>gcc</strong></span>. This is used for declaring
601 functions which take a variable number of arguments, with the same
602 syntax as <code class="function">scanf()</code>. It allows the compiler to type-check the arguments
603 passed to the function. See the GNU C documentation for details.
604 </p>
605 <div class="variablelist"><table border="0">
606 <col align="left" valign="top">
607 <tbody>
608 <tr>
609 <td><p><span class="term"><em class="parameter"><code>format_idx</code></em> :</span></p></td>
610 <td>the index of the argument corresponding to
611 the format string (The arguments are numbered from 1)</td>
612 </tr>
613 <tr>
614 <td><p><span class="term"><em class="parameter"><code>arg_idx</code></em> :</span></p></td>
615 <td>the index of the first of the format arguments</td>
616 </tr>
617 </tbody>
618 </table></div>
619 </div>
620 <hr>
621 <div class="refsect2">
622 <a name="G-GNUC-FORMAT:CAPS"></a><h3>G_GNUC_FORMAT()</h3>
623 <pre class="programlisting">#define             G_GNUC_FORMAT( arg_idx )</pre>
624 <p>
625 Expands to the GNU C <code class="literal">format_arg</code> function attribute
626 if the compiler is <span class="command"><strong>gcc</strong></span>. This function attribute
627 specifies that a function takes a format string for a <code class="function">printf()</code>,
628 <code class="function">scanf()</code>, <code class="function">strftime()</code> or <code class="function">strfmon()</code> style function and modifies it,
629 so that the result can be passed to a <code class="function">printf()</code>, <code class="function">scanf()</code>, <code class="function">strftime()</code>
630 or <code class="function">strfmon()</code> style function (with the remaining arguments to the
631 format function the same as they would have been for the unmodified
632 string). See the GNU C documentation for details.
633 </p>
634 <p>
635 </p>
636 <div class="informalexample"><pre class="programlisting">
637 gchar *g_dgettext (gchar *domain_name, gchar *msgid) G_GNUC_FORMAT (2);
638 </pre></div>
639 <p>
640 </p>
641 <div class="variablelist"><table border="0">
642 <col align="left" valign="top">
643 <tbody><tr>
644 <td><p><span class="term"><em class="parameter"><code>arg_idx</code></em> :</span></p></td>
645 <td>the index of the argument</td>
646 </tr></tbody>
647 </table></div>
648 </div>
649 <hr>
650 <div class="refsect2">
651 <a name="G-GNUC-NULL-TERMINATED:CAPS"></a><h3>G_GNUC_NULL_TERMINATED</h3>
652 <pre class="programlisting">#define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
653 </pre>
654 <p>
655 Expands to the GNU C <code class="literal">sentinel</code> function attribute
656 if the compiler is <span class="command"><strong>gcc</strong></span>, or "" if it isn't. This
657 function attribute only applies to variadic functions and instructs
658 the compiler to check that the argument list is terminated with an
659 explicit <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>. See the GNU C documentation for details.
660 </p>
661 <p class="since">Since 2.8</p>
662 </div>
663 <hr>
664 <div class="refsect2">
665 <a name="G-GNUC-WARN-UNUSED-RESULT:CAPS"></a><h3>G_GNUC_WARN_UNUSED_RESULT</h3>
666 <pre class="programlisting">#define             G_GNUC_WARN_UNUSED_RESULT</pre>
667 <p>
668 Expands to the GNU C <code class="literal">warn_unused_result</code> function
669 attribute if the compiler is <span class="command"><strong>gcc</strong></span>, or "" if it isn't.
670 This function attribute makes the compiler emit a warning if the result
671 of a function call is ignored. See the GNU C documentation for details.
672 </p>
673 <p class="since">Since 2.10</p>
674 </div>
675 <hr>
676 <div class="refsect2">
677 <a name="G-GNUC-FUNCTION:CAPS"></a><h3>G_GNUC_FUNCTION</h3>
678 <pre class="programlisting">#define G_GNUC_FUNCTION         __FUNCTION__
679 </pre>
680 <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
681 <h3 class="title">Warning</h3>
682 <p><code class="literal">G_GNUC_FUNCTION</code> has been deprecated since version 2.16 and should not be used in newly-written code. Use <a class="link" href="glib-Miscellaneous-Macros.html#G-STRFUNC:CAPS" title="G_STRFUNC"><span class="type">G_STRFUNC</span></a> instead</p>
683 </div>
684 <p>
685 Expands to "" on all modern compilers, and to
686 <code class="literal">__FUNCTION__</code> on <span class="command"><strong>gcc</strong></span> version 2.x.
687 Don't use it.
688 </p>
689 </div>
690 <hr>
691 <div class="refsect2">
692 <a name="G-GNUC-PRETTY-FUNCTION:CAPS"></a><h3>G_GNUC_PRETTY_FUNCTION</h3>
693 <pre class="programlisting">#define G_GNUC_PRETTY_FUNCTION  __PRETTY_FUNCTION__
694 </pre>
695 <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
696 <h3 class="title">Warning</h3>
697 <p><code class="literal">G_GNUC_PRETTY_FUNCTION</code> has been deprecated since version 2.16 and should not be used in newly-written code. Use <a class="link" href="glib-Miscellaneous-Macros.html#G-STRFUNC:CAPS" title="G_STRFUNC"><span class="type">G_STRFUNC</span></a> instead</p>
698 </div>
699 <p>
700 Expands to "" on all modern compilers, and to
701 <code class="literal">__PRETTY_FUNCTION__</code> on <span class="command"><strong>gcc</strong></span>
702 version 2.x. Don't use it.
703 </p>
704 </div>
705 <hr>
706 <div class="refsect2">
707 <a name="G-GNUC-NO-INSTRUMENT:CAPS"></a><h3>G_GNUC_NO_INSTRUMENT</h3>
708 <pre class="programlisting">#define             G_GNUC_NO_INSTRUMENT</pre>
709 <p>
710 Expands to the GNU C <code class="literal">no_instrument_function</code> function
711 attribute if the compiler is <span class="command"><strong>gcc</strong></span>. Functions with this
712 attribute will not be instrumented for profiling, when the compiler is
713 called with the <code class="option">-finstrument-functions</code> option.
714 See the GNU C documentation for details.
715 </p>
716 </div>
717 <hr>
718 <div class="refsect2">
719 <a name="G-HAVE-GNUC-VISIBILITY:CAPS"></a><h3>G_HAVE_GNUC_VISIBILITY</h3>
720 <pre class="programlisting">#define G_HAVE_GNUC_VISIBILITY 1
721 </pre>
722 </div>
723 <hr>
724 <div class="refsect2">
725 <a name="G-GNUC-INTERNAL:CAPS"></a><h3>G_GNUC_INTERNAL</h3>
726 <pre class="programlisting">#define G_GNUC_INTERNAL __attribute__((visibility("hidden")))
727 </pre>
728 <p>
729 This attribute can be used for marking library functions as being used
730 internally to the library only, which may allow the compiler to handle
731 function calls more efficiently. Note that static functions do not need
732 to be marked as internal in this way. See the GNU C documentation for
733 details.
734 </p>
735 <p>
736 When using a compiler that supports the GNU C hidden visibility attribute,
737 this macro expands to <code class="literal">__attribute__((visibility("hidden")))</code>.
738 When using the Sun Studio compiler, it expands to <code class="literal">__hidden</code>.
739 </p>
740 <p>
741 Note that for portability, the attribute should be placed before the
742 function declaration. While GCC allows the macro after the declaration,
743 Sun Studio does not.
744 </p>
745 <p>
746 </p>
747 <div class="informalexample"><pre class="programlisting">
748 G_GNUC_INTERNAL
749 void _g_log_fallback_handler (const gchar    *log_domain,
750                               GLogLevelFlags  log_level,
751                               const gchar    *message,
752                               gpointer        unused_data);
753 </pre></div>
754 <p>
755 </p>
756 <p class="since">Since 2.6</p>
757 </div>
758 <hr>
759 <div class="refsect2">
760 <a name="G-GNUC-MAY-ALIAS:CAPS"></a><h3>G_GNUC_MAY_ALIAS</h3>
761 <pre class="programlisting">#  define G_GNUC_MAY_ALIAS __attribute__((may_alias))
762 </pre>
763 <p>
764 Expands to the GNU C <code class="literal">may_alias</code> type attribute
765 if the compiler is <span class="command"><strong>gcc</strong></span>. Types with this attribute
766 will not be subjected to type-based alias analysis, but are assumed
767 to alias with any other type, just like char.
768 See the GNU C documentation for details.
769 </p>
770 <p class="since">Since 2.14</p>
771 </div>
772 <hr>
773 <div class="refsect2">
774 <a name="G-DEPRECATED:CAPS"></a><h3>G_DEPRECATED</h3>
775 <pre class="programlisting">#define G_DEPRECATED __attribute__((__deprecated__))
776 </pre>
777 <p>
778 This macro is similar to <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-DEPRECATED:CAPS" title="G_GNUC_DEPRECATED"><code class="literal">G_GNUC_DEPRECATED</code></a>, and can be used to mark
779 functions declarations as deprecated. Unlike <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-DEPRECATED:CAPS" title="G_GNUC_DEPRECATED"><code class="literal">G_GNUC_DEPRECATED</code></a>, it is
780 meant to be portable across different compilers and must be placed
781 before the function declaration.
782 </p>
783 <p class="since">Since 2.32</p>
784 </div>
785 <hr>
786 <div class="refsect2">
787 <a name="G-DEPRECATED-FOR:CAPS"></a><h3>G_DEPRECATED_FOR()</h3>
788 <pre class="programlisting">#define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead")))
789 </pre>
790 <p>
791 This macro is similar to <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-DEPRECATED-FOR:CAPS" title="G_GNUC_DEPRECATED_FOR()"><code class="literal">G_GNUC_DEPRECATED_FOR</code></a>, and can be used to mark
792 functions declarations as deprecated. Unlike <a class="link" href="glib-Miscellaneous-Macros.html#G-GNUC-DEPRECATED-FOR:CAPS" title="G_GNUC_DEPRECATED_FOR()"><code class="literal">G_GNUC_DEPRECATED_FOR</code></a>, it is
793 meant to be portable across different compilers and must be placed
794 before the function declaration.
795 </p>
796 <p class="since">Since 2.32</p>
797 </div>
798 <hr>
799 <div class="refsect2">
800 <a name="G-UNAVAILABLE:CAPS"></a><h3>G_UNAVAILABLE()</h3>
801 <pre class="programlisting">#define G_UNAVAILABLE(maj,min) __attribute__((deprecated("Not available before " #maj "." #min)))
802 </pre>
803 <p>
804 This macro can be used to mark a function declaration as unavailable.
805 It must be placed before the function declaration. Use of a function
806 that has been annotated with this macros will produce a compiler warning.
807 </p>
808 <p class="since">Since 2.32</p>
809 </div>
810 <hr>
811 <div class="refsect2">
812 <a name="G-LIKELY:CAPS"></a><h3>G_LIKELY()</h3>
813 <pre class="programlisting">#define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 1))
814 </pre>
815 <p>
816 Hints the compiler that the expression is likely to evaluate to
817 a true value. The compiler may use this information for optimizations.
818 </p>
819 <p>
820 </p>
821 <div class="informalexample"><pre class="programlisting">
822 if (G_LIKELY (random () != 1))
823   g_print ("not one");
824 </pre></div>
825 <p>
826 </p>
827 <div class="variablelist"><table border="0">
828 <col align="left" valign="top">
829 <tbody>
830 <tr>
831 <td><p><span class="term"><em class="parameter"><code>expr</code></em> :</span></p></td>
832 <td>the expression</td>
833 </tr>
834 <tr>
835 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
836 <td>the value of <em class="parameter"><code>expr</code></em>
837 </td>
838 </tr>
839 </tbody>
840 </table></div>
841 <p class="since">Since 2.2</p>
842 </div>
843 <hr>
844 <div class="refsect2">
845 <a name="G-UNLIKELY:CAPS"></a><h3>G_UNLIKELY()</h3>
846 <pre class="programlisting">#define G_UNLIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 0))
847 </pre>
848 <p>
849 Hints the compiler that the expression is unlikely to evaluate to
850 a true value. The compiler may use this information for optimizations.
851 </p>
852 <p>
853 </p>
854 <div class="informalexample"><pre class="programlisting">
855 if (G_UNLIKELY (random () == 1))
856   g_print ("a random one");
857 </pre></div>
858 <p>
859 </p>
860 <div class="variablelist"><table border="0">
861 <col align="left" valign="top">
862 <tbody>
863 <tr>
864 <td><p><span class="term"><em class="parameter"><code>expr</code></em> :</span></p></td>
865 <td>the expression</td>
866 </tr>
867 <tr>
868 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
869 <td>the value of <em class="parameter"><code>expr</code></em>
870 </td>
871 </tr>
872 </tbody>
873 </table></div>
874 <p class="since">Since 2.2</p>
875 </div>
876 <hr>
877 <div class="refsect2">
878 <a name="G-STRLOC:CAPS"></a><h3>G_STRLOC</h3>
879 <pre class="programlisting">#  define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__) ":" __PRETTY_FUNCTION__ "()"
880 </pre>
881 <p>
882 Expands to a string identifying the current code position.
883 </p>
884 </div>
885 <hr>
886 <div class="refsect2">
887 <a name="G-STRFUNC:CAPS"></a><h3>G_STRFUNC</h3>
888 <pre class="programlisting">#  define G_STRFUNC     ((const char*) (__PRETTY_FUNCTION__))
889 </pre>
890 <p>
891 Expands to a string identifying the current function.
892 </p>
893 <p class="since">Since 2.4</p>
894 </div>
895 </div>
896 </div>
897 <div class="footer">
898 <hr>
899           Generated by GTK-Doc V1.18</div>
900 </body>
901 </html>