~ubuntu-branches/ubuntu/utopic/glib2.0/utopic

« back to all changes in this revision

Viewing changes to docs/reference/glib/tmpl/macros_misc.sgml

Tags: upstream-2.12.12
ImportĀ upstreamĀ versionĀ 2.12.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!-- ##### SECTION Title ##### -->
 
2
Miscellaneous Macros
 
3
 
 
4
<!-- ##### SECTION Short_Description ##### -->
 
5
specialized macros which are not used often.
 
6
 
 
7
<!-- ##### SECTION Long_Description ##### -->
 
8
<para>
 
9
These macros provide more specialized features which are not needed so often
 
10
by application programmers.
 
11
</para>
 
12
 
 
13
<!-- ##### SECTION See_Also ##### -->
 
14
<para>
 
15
 
 
16
</para>
 
17
 
 
18
<!-- ##### SECTION Stability_Level ##### -->
 
19
 
 
20
 
 
21
<!-- ##### MACRO G_INLINE_FUNC ##### -->
 
22
<para>
 
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.
 
29
</para>
 
30
<para>
 
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.
 
34
</para>
 
35
 
 
36
 
 
37
 
 
38
<!-- ##### MACRO G_STMT_START ##### -->
 
39
<para>
 
40
Used within multi-statement macros so that they can be used in places where
 
41
only one statement is expected by the compiler.
 
42
</para>
 
43
 
 
44
 
 
45
 
 
46
<!-- ##### MACRO G_STMT_END ##### -->
 
47
<para>
 
48
Used within multi-statement macros so that they can be used in places where
 
49
only one statement is expected by the compiler.
 
50
</para>
 
51
 
 
52
 
 
53
 
 
54
<!-- ##### MACRO G_BEGIN_DECLS ##### -->
 
55
<para>
 
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> 
 
58
around the header.
 
59
</para>
 
60
 
 
61
 
 
62
 
 
63
<!-- ##### MACRO G_END_DECLS ##### -->
 
64
<para>
 
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> 
 
67
around the header.
 
68
</para>
 
69
 
 
70
 
 
71
 
 
72
<!-- ##### MACRO G_N_ELEMENTS ##### -->
 
73
<para>
 
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.
 
78
</para>
 
79
 
 
80
@arr: the array
 
81
 
 
82
 
 
83
<!-- ##### MACRO G_VA_COPY ##### -->
 
84
<para>
 
85
Portable way to copy <type>va_list</type> variables.
 
86
</para>
 
87
<para>
 
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.
 
91
</para>
 
92
 
 
93
@ap1: the <type>va_list</type> variable to place a copy of @ap2 in.
 
94
@ap2: a <type>va_list</type>.
 
95
 
 
96
 
 
97
<!-- ##### MACRO G_STRINGIFY ##### -->
 
98
<para>
 
99
Accepts a macro or a string and converts it into a string.
 
100
</para>
 
101
 
 
102
@macro_or_string: a macro or a string.
 
103
 
 
104
 
 
105
<!-- ##### MACRO G_GNUC_EXTENSION ##### -->
 
106
<para>
 
107
Expands to <literal>__extension__</literal> when <command>gcc</command> is 
 
108
used as the compiler.
 
109
This simply tells <command>gcc</command> not to warn about the following non-standard code
 
110
when compiling with the <option>-pedantic</option> option.
 
111
</para>
 
112
 
 
113
 
 
114
 
 
115
<!-- ##### MACRO G_GNUC_CONST ##### -->
 
116
<para>
 
117
Expands to the GNU C <literal>const</literal> function attribute if the compiler is 
 
118
<command>gcc</command>. Declaring a function as const enables better optimization of calls 
 
119
to the function. A const function doesn't examine any values except its parameters, and has no 
 
120
effects except its return value. See the GNU C documentation for details. 
 
121
</para>
 
122
<note><para>
 
123
A function that has pointer arguments and examines the data pointed to 
 
124
must <emphasis>not</emphasis> be declared const. Likewise, a function that 
 
125
calls a non-const function usually must not be const. It doesn't make sense 
 
126
for a const function to return void.
 
127
</para></note>
 
128
 
 
129
 
 
130
 
 
131
<!-- ##### MACRO G_GNUC_PURE ##### -->
 
132
<para>
 
133
Expands to the GNU C <literal>pure</literal> function attribute if the compiler is 
 
134
<command>gcc</command>. Declaring a function as pure enables better optimization of 
 
135
calls to the function. A pure function has no effects except its return value and the 
 
136
return value depends only on the parameters and/or global variables.
 
137
See the GNU C documentation for details. 
 
138
</para>
 
139
 
 
140
 
 
141
 
 
142
<!-- ##### MACRO G_GNUC_MALLOC ##### -->
 
143
<para>
 
144
Expands to the GNU C <literal>malloc</literal> function attribute if the compiler is 
 
145
<command>gcc</command>. Declaring a function as malloc enables better optimization of the 
 
146
function. A function can have the malloc attribute if it returns a pointer which is guaranteed
 
147
to not alias with any other pointer when the function returns (in practice, this means newly 
 
148
allocated memory).  
 
149
See the GNU C documentation for details. 
 
150
</para>
 
151
 
 
152
@Since: 2.6
 
153
 
 
154
 
 
155
<!-- ##### MACRO G_GNUC_DEPRECATED ##### -->
 
156
<para>
 
157
Expands to the GNU C <literal>deprecated</literal> attribute if the compiler 
 
158
is <command>gcc</command>.
 
159
It can be used to mark typedefs, variables and functions as deprecated. 
 
160
When called with the <option>-Wdeprecated</option> option, the compiler will 
 
161
generate warnings when deprecated interfaces are used.
 
162
See the GNU C documentation for details. 
 
163
</para>
 
164
 
 
165
@Since: 2.2
 
166
 
 
167
 
 
168
<!-- ##### MACRO G_GNUC_NORETURN ##### -->
 
169
<para>
 
170
Expands to the GNU C <literal>noreturn</literal> function attribute if the 
 
171
compiler is <command>gcc</command>. It is used for declaring functions which never return.
 
172
It enables optimization of the function, and avoids possible compiler
 
173
warnings. See the GNU C documentation for details. 
 
174
</para>
 
175
 
 
176
 
 
177
 
 
178
<!-- ##### MACRO G_GNUC_UNUSED ##### -->
 
179
<para>
 
180
Expands to the GNU C <literal>unused</literal> function attribute if the compiler is 
 
181
<command>gcc</command>. It is used for declaring functions which may never be used.
 
182
It avoids possible compiler warnings. See the GNU C documentation for details. 
 
183
</para>
 
184
 
 
185
 
 
186
 
 
187
<!-- ##### MACRO G_GNUC_PRINTF ##### -->
 
188
<para>
 
189
Expands to the GNU C <literal>format</literal> function attribute if the compiler is 
 
190
<command>gcc</command>. This is used for declaring functions which take a variable number of
 
191
arguments, with the same syntax as <function>printf()</function>.
 
192
It allows the compiler to type-check the arguments passed to the function.
 
193
See the GNU C documentation for details. 
 
194
</para>
 
195
<informalexample><programlisting>
 
196
gint g_snprintf (gchar  *string,
 
197
                 gulong       n,
 
198
                 gchar const *format,
 
199
                 ...) G_GNUC_PRINTF (3, 4);
 
200
</programlisting></informalexample>
 
201
 
 
202
@format_idx: the index of the argument corresponding to the format string.
 
203
(The arguments are numbered from 1).
 
204
@arg_idx: the index of the first of the format arguments.
 
205
 
 
206
 
 
207
<!-- ##### MACRO G_GNUC_SCANF ##### -->
 
208
<para>
 
209
Expands to the GNU C <literal>format</literal> function attribute if the compiler is <command>gcc</command>.
 
210
This is used for declaring functions which take a variable number of
 
211
arguments, with the same syntax as <function>scanf()</function>.
 
212
It allows the compiler to type-check the arguments passed to the function.
 
213
See the GNU C documentation for details. 
 
214
</para>
 
215
 
 
216
@format_idx: the index of the argument corresponding to the format string.
 
217
(The arguments are numbered from 1).
 
218
@arg_idx: the index of the first of the format arguments.
 
219
 
 
220
 
 
221
<!-- ##### MACRO G_GNUC_FORMAT ##### -->
 
222
<para>
 
223
Expands to the GNU C <literal>format_arg</literal> function attribute if the compiler is <command>gcc</command>.
 
224
This function attribute specifies that a function takes a format
 
225
string for a <function>printf()</function>, <function>scanf()</function>, 
 
226
<function>strftime()</function> or <function>strfmon()</function> style
 
227
function and modifies it, so that the result can be passed to a 
 
228
<function>printf()</function>, <function>scanf()</function>, 
 
229
<function>strftime()</function> or <function>strfmon()</function> style 
 
230
function (with the remaining arguments to the format function the same as 
 
231
they would have been for the unmodified string). 
 
232
See the GNU C documentation for details. 
 
233
</para>
 
234
<informalexample><programlisting>
 
235
gchar *g_dgettext (gchar *domain_name, gchar *msgid) G_GNUC_FORMAT (2);
 
236
</programlisting></informalexample>
 
237
 
 
238
@arg_idx: the index of the argument.
 
239
 
 
240
 
 
241
<!-- ##### MACRO G_GNUC_NULL_TERMINATED ##### -->
 
242
<para>
 
243
Expands to the GNU C <literal>sentinel</literal> function attribute if the 
 
244
compiler is <command>gcc</command>, or "" if it isn't. This function attribute
 
245
only applies to variadic functions and instructs the compiler to check that 
 
246
the argument list is terminated with an explicit %NULL.
 
247
See the GNU C documentation for details. 
 
248
</para>
 
249
 
 
250
Since: 2.8
 
251
 
 
252
 
 
253
 
 
254
<!-- ##### MACRO G_GNUC_WARN_UNUSED_RESULT ##### -->
 
255
<para>
 
256
Expands to the GNU C <literal>warn_unused_ersult</literal> function attribute 
 
257
if the compiler is <command>gcc</command>, or "" if it isn't. This function 
 
258
attribute makes the compiler emit a warning if the result of a function call
 
259
is ignored. See the GNU C documentation for details. 
 
260
</para>
 
261
 
 
262
@Since: 2.10
 
263
 
 
264
 
 
265
<!-- ##### MACRO G_GNUC_FUNCTION ##### -->
 
266
<para>
 
267
Expands to the GNU C <literal>__FUNCTION__</literal> variable if the 
 
268
compiler is <command>gcc</command>, or "" if it isn't. The GNU C 
 
269
<literal>__FUNCTION__</literal> variable contains the name of the 
 
270
current function. See the GNU C documentation for details. 
 
271
</para>
 
272
 
 
273
 
 
274
 
 
275
<!-- ##### MACRO G_GNUC_PRETTY_FUNCTION ##### -->
 
276
<para>
 
277
Expands to the GNU C <literal>__PRETTY_FUNCTION__</literal> variable 
 
278
if the compiler is <command>gcc</command>, or "" if it isn't.
 
279
The GNU C <literal>__PRETTY_FUNCTION__</literal> variable contains the 
 
280
name of the current function. For a C program this is the same as the 
 
281
<literal>__FUNCTION__</literal> variable but for C++ it also includes 
 
282
extra information such as the class and function prototype. See the 
 
283
GNU C documentation for details. 
 
284
</para>
 
285
 
 
286
 
 
287
 
 
288
<!-- ##### MACRO G_GNUC_NO_INSTRUMENT ##### -->
 
289
<para>
 
290
Expands to the GNU C <literal>no_instrument_function</literal> function 
 
291
attribute if the compiler is <command>gcc</command>. Functions with this 
 
292
attribute will not be 
 
293
instrumented for profiling, when the compiler is called with the
 
294
<option>-finstrument-functions</option> option.
 
295
See the GNU C documentation for details. 
 
296
</para>
 
297
 
 
298
 
 
299
 
 
300
<!-- ##### MACRO G_HAVE_GNUC_VISIBILITY ##### -->
 
301
<para>
 
302
This macro is defined as 1 if the the compiler supports ELF visibility 
 
303
attributes (currently only <command>gcc</command>).
 
304
</para>
 
305
 
 
306
Since: 2.6
 
307
 
 
308
 
 
309
 
 
310
<!-- ##### MACRO G_GNUC_INTERNAL ##### -->
 
311
<para>
 
312
Expands to the GNU C <literal>visibility(hidden)</literal> attribute if the 
 
313
compiler supports it  (currently only <command>gcc</command>). This attribute 
 
314
can be used for marking library functions as being used internally to the lib 
 
315
only, to not create inefficient PLT entries. Note that static functions do not 
 
316
need to be marked as internal in this way. See the GNU C documentation for details. 
 
317
</para>
 
318
 
 
319
Since: 2.6
 
320
 
 
321
 
 
322
 
 
323
<!-- ##### MACRO G_LIKELY ##### -->
 
324
<para>
 
325
Hints the compiler that the expression is likely to evaluate to a true
 
326
value. The compiler may use this information for optimizations.
 
327
</para>
 
328
<informalexample><programlisting>
 
329
if (G_LIKELY (random () != 1))
 
330
  g_print ("not one");
 
331
</programlisting></informalexample>
 
332
 
 
333
@expr: the expression
 
334
@Since: 2.2
 
335
 
 
336
 
 
337
<!-- ##### MACRO G_UNLIKELY ##### -->
 
338
<para>
 
339
Hints the compiler that the expression is unlikely to evaluate to a true
 
340
value. The compiler may use this information for optimizations.
 
341
</para>
 
342
<informalexample><programlisting>
 
343
if (G_UNLIKELY (random () == 1))
 
344
  g_print ("a random one");
 
345
</programlisting></informalexample>
 
346
 
 
347
@expr: the expression
 
348
@Since: 2.2
 
349
 
 
350
 
 
351
<!-- ##### MACRO G_STRLOC ##### -->
 
352
<para>
 
353
Expands to a string identifying the current code position. 
 
354
</para>
 
355
 
 
356
 
 
357
 
 
358
<!-- ##### MACRO G_STRFUNC ##### -->
 
359
<para>
 
360
Expands to a string identifying the current function. 
 
361
</para>
 
362
 
 
363
@Since: 2.4
 
364
 
 
365
 
 
366
<!-- ##### MACRO G_GINT16_MODIFIER ##### -->
 
367
<para>
 
368
The platform dependent length modifier for constructing printf() conversion
 
369
specifiers for values of type #gint16 or #guint16. It is a string literal, 
 
370
but doesn't include the percent-sign, such that you can add precision and 
 
371
length modifiers between percent-sign and conversion specifier and append a 
 
372
conversion specifier.
 
373
</para>
 
374
 
 
375
<para>
 
376
The following example prints "0x7b";
 
377
<informalexample>
 
378
<programlisting>
 
379
gint16 value = 123;
 
380
g_print ("%#" G_GINT16_MODIFIER "x", value);
 
381
</programlisting>
 
382
</informalexample>
 
383
</para>
 
384
 
 
385
@Since: 2.4
 
386
 
 
387
 
 
388
<!-- ##### MACRO G_GINT16_FORMAT ##### -->
 
389
<para>
 
390
This is the platform dependent conversion specifier for scanning and
 
391
printing values of type #gint16. It is a string literal, but doesn't
 
392
include the percent-sign, such that you can add precision and length
 
393
modifiers between percent-sign and conversion specifier.
 
394
</para>
 
395
 
 
396
<para>
 
397
<informalexample>
 
398
<programlisting>
 
399
gint16 in;
 
400
gint32 out;
 
401
sscanf ("42", "%" G_GINT16_FORMAT, &amp;in)
 
402
out = in * 1000;
 
403
g_print ("%" G_GINT32_FORMAT, out);
 
404
</programlisting>
 
405
</informalexample>
 
406
</para>
 
407
 
 
408
 
 
409
 
 
410
<!-- ##### MACRO G_GUINT16_FORMAT ##### -->
 
411
<para>
 
412
This is the platform dependent conversion specifier for scanning and
 
413
printing values of type #guint16. See also #G_GINT16_FORMAT.
 
414
</para>
 
415
 
 
416
 
 
417
 
 
418
<!-- ##### MACRO G_GINT32_MODIFIER ##### -->
 
419
<para>
 
420
The platform dependent length modifier for constructing printf() conversion
 
421
specifiers for values of type #gint32 or #guint32. See also #G_GINT16_MODIFIER.
 
422
</para>
 
423
 
 
424
@Since: 2.4
 
425
 
 
426
 
 
427
<!-- ##### MACRO G_GINT32_FORMAT ##### -->
 
428
<para>
 
429
This is the platform dependent conversion specifier for scanning and
 
430
printing values of type #gint32. See also #G_GINT16_FORMAT.
 
431
</para>
 
432
 
 
433
 
 
434
 
 
435
<!-- ##### MACRO G_GUINT32_FORMAT ##### -->
 
436
<para>
 
437
This is the platform dependent conversion specifier for scanning and
 
438
printing values of type #guint32. See also #G_GINT16_FORMAT.
 
439
</para>
 
440
 
 
441
 
 
442
 
 
443
<!-- ##### MACRO G_GINT64_MODIFIER ##### -->
 
444
<para>
 
445
The platform dependent length modifier for constructing printf() conversion
 
446
specifiers for values of type #gint64 or #guint64. See also #G_GINT16_MODIFIER.
 
447
</para>
 
448
 
 
449
<note>
 
450
<para>
 
451
Some platforms do not support printing 64 bit integers,
 
452
even though the types are supported. On such platforms #G_GINT64_MODIFIER
 
453
is not defined.
 
454
</para>
 
455
</note>
 
456
 
 
457
@Since: 2.4
 
458
 
 
459
 
 
460
<!-- ##### MACRO G_GINT64_FORMAT ##### -->
 
461
<para>
 
462
This is the platform dependent conversion specifier for scanning and
 
463
printing values of type #gint64. See also #G_GINT16_FORMAT.
 
464
</para>
 
465
 
 
466
<note>
 
467
<para>
 
468
Some platforms do not support scanning and printing 64 bit integers,
 
469
even though the types are supported. On such platforms #G_GINT64_FORMAT
 
470
is not defined. Note that scanf() may not support 64 bit integers, even
 
471
if #G_GINT64_FORMAT is defined. Due to its weak error handling, scanf() is not 
 
472
recommended for parsing anyway; consider using g_strtoull() instead.
 
473
</para>
 
474
</note>
 
475
 
 
476
 
 
477
 
 
478
<!-- ##### MACRO G_GUINT64_FORMAT ##### -->
 
479
<para>
 
480
This is the platform dependent conversion specifier for scanning and
 
481
printing values of type #guint64. See also #G_GINT16_FORMAT.
 
482
</para>
 
483
 
 
484
<note>
 
485
<para>
 
486
Some platforms do not support scanning and printing 64 bit integers,
 
487
even though the types are supported. On such platforms #G_GUINT64_FORMAT
 
488
is not defined.  Note that scanf() may not support 64 bit integers, even
 
489
if #G_GINT64_FORMAT is defined. Due to its weak error handling, scanf() is not 
 
490
recommended for parsing anyway; consider using g_strtoull() instead.
 
491
</para>
 
492
</note>
 
493
 
 
494
 
 
495
 
 
496
<!-- ##### MACRO G_GSIZE_MODIFIER ##### -->
 
497
<para>
 
498
The platform dependent length modifier for constructing printf() conversion
 
499
specifiers for values of type #gsize or #gssize. See also #G_GINT16_MODIFIER.
 
500
</para>
 
501
 
 
502
@Since: 2.6
 
503
 
 
504
 
 
505
<!-- ##### MACRO G_GSIZE_FORMAT ##### -->
 
506
<para>
 
507
This is the platform dependent conversion specifier for scanning and
 
508
printing values of type #gsize. See also #G_GINT16_FORMAT.
 
509
</para>
 
510
 
 
511
@Since: 2.6
 
512
 
 
513
 
 
514
<!-- ##### MACRO G_GSSIZE_FORMAT ##### -->
 
515
<para>
 
516
This is the platform dependent conversion specifier for scanning and
 
517
printing values of type #gssize. See also #G_GINT16_FORMAT.
 
518
</para>
 
519
 
 
520
@Since: 2.6
 
521
 
 
522