Update.
[platform/upstream/glib.git] / docs / reference / glib / tmpl / macros_misc.sgml
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 <!-- ##### MACRO G_INLINE_FUNC ##### -->
19 <para>
20 Used to declare inline functions. If inline functions are not supported on
21 the particular platform, the macro evaluates to the empty string.
22 </para>
23
24
25
26 <!-- ##### MACRO G_STMT_START ##### -->
27 <para>
28 Used within multi-statement macros so that they can be used in places where
29 only one statement is expected by the compiler.
30 </para>
31
32
33
34 <!-- ##### MACRO G_STMT_END ##### -->
35 <para>
36 Used within multi-statement macros so that they can be used in places where
37 only one statement is expected by the compiler.
38 </para>
39
40
41
42 <!-- ##### MACRO G_BEGIN_DECLS ##### -->
43 <para>
44 Used (along with #G_END_DECLS) to bracket header files. If the
45 compiler in use is a C++ compiler, adds 'extern "C"' around the header.
46 </para>
47
48
49
50 <!-- ##### MACRO G_END_DECLS ##### -->
51 <para>
52 Used (along with #G_BEGIN_DECLS) to bracket header files. If the
53 compiler in use is a C++ compiler, adds <literal>extern "C"</literal> 
54 around the header.
55 </para>
56
57
58
59 <!-- ##### MACRO G_N_ELEMENTS ##### -->
60 <para>
61 Determines the number of elements in an array. The array must be
62 declared so the compiler knows its size at compile-time; this 
63 macro will not work on an array allocated on the heap, only static
64 arrays or arrays on the stack.
65 </para>
66
67 @arr: the array
68
69
70 <!-- ##### MACRO G_VA_COPY ##### -->
71 <para>
72 Portable way to copy <type>va_list</type> variables.
73 </para>
74 <para>
75 In order to use this function, you must include <filename>string.h</filename> 
76 yourself, because this macro may use <function>memmove()</function> and GLib 
77 does not include <function>string.h</function> for you.
78 </para>
79
80 @ap1: the <type>va_list</type> variable to place a copy of @ap2 in.
81 @ap2: a <type>va_list</type>.
82
83
84 <!-- ##### MACRO G_STRINGIFY ##### -->
85 <para>
86 Accepts a macro or a string and converts it into a string.
87 </para>
88
89 @macro_or_string: a macro or a string.
90
91
92 <!-- ##### MACRO G_GNUC_EXTENSION ##### -->
93 <para>
94 Expands to <literal>__extension__</literal> when GNU C is used as the compiler.
95 This simply tells GNU C not to warn about the following non-standard code
96 when compiling with the <literal>-pedantic</literal> option.
97 </para>
98
99
100
101 <!-- ##### MACRO G_GNUC_NORETURN ##### -->
102 <para>
103 Expands to the GNU C noreturn function attribute if the compiler is GNU C.
104 It is used for declaring functions which never return.
105 It enables optimization of the function, and avoids possible compiler
106 warnings. See the GNU C documentation for details. 
107 </para>
108
109
110
111 <!-- ##### MACRO G_GNUC_UNUSED ##### -->
112 <para>
113 Expands to the GNU C unused function attribute if the compiler is GNU C.
114 It is used for declaring functions which may never be used.
115 It avoids possible compiler warnings. See the GNU C documentation for details. 
116 </para>
117
118
119
120 <!-- ##### MACRO G_GNUC_PURE ##### -->
121 <para>
122 Expands to the GNU C pure function attribute if the compiler is GNU C.
123 Declaring a function as pure enables better optimization of the function.
124 A pure function has no effects except its return value and the return 
125 value depends only on the parameters and/or global variables.
126 See the GNU C documentation for details. 
127 </para>
128
129
130 <!-- ##### MACRO G_GNUC_CONST ##### -->
131 <para>
132 Expands to the GNU C const function attribute if the compiler is GNU C.
133 Declaring a function as const enables better optimization of the function.
134 A const function doesn't examine any values except its parameters,
135 and has no effects except its return value.
136 See the GNU C documentation for details. 
137 </para>
138 <note><para>
139 A function that has pointer arguments and examines the data pointed to 
140 must <emphasis>not</emphasis> be declared const. Likewise, a function that 
141 calls a non-const function usually must not be const. It doesn't make sense 
142 for a const function to return void.
143 </para></note>
144
145
146 <!-- ##### MACRO G_GNUC_PRINTF ##### -->
147 <para>
148 Expands to the GNU C format function attribute if the compiler is GNU C.
149 This is used for declaring functions which take a variable number of
150 arguments, with the same syntax as <function>printf()</function>.
151 It allows the compiler to type-check the arguments passed to the function.
152 See the GNU C documentation for details. 
153 </para>
154 <informalexample><programlisting>
155 gint g_snprintf (gchar  *string,
156                  gulong       n,
157                  gchar const *format,
158                  ...) G_GNUC_PRINTF (3, 4);
159 </programlisting></informalexample>
160
161 @format_idx: the index of the argument corresponding to the format string.
162 (The arguments are numbered from 1).
163 @arg_idx: the index of the first of the format arguments.
164
165
166 <!-- ##### MACRO G_GNUC_SCANF ##### -->
167 <para>
168 Expands to the GNU C format function attribute if the compiler is GNU C.
169 This is used for declaring functions which take a variable number of
170 arguments, with the same syntax as <function>scanf()</function>.
171 It allows the compiler to type-check the arguments passed to the function.
172 See the GNU C documentation for details. 
173 </para>
174
175 @format_idx: the index of the argument corresponding to the format string.
176 (The arguments are numbered from 1).
177 @arg_idx: the index of the first of the format arguments.
178
179
180 <!-- ##### MACRO G_GNUC_FORMAT ##### -->
181 <para>
182 Expands to the GNU C format_arg function attribute if the compiler is GNU C.
183 The format_arg function attribute specifies that a function takes a format
184 string for a <function>printf()</function>, <function>scanf()</function>, 
185 <function>strftime()</function> or <function>strfmon()</function> style
186 function and modifies it, so that the result can be passed to a 
187 <function>printf()</function>, <function>scanf()</function>, 
188 <function>strftime()</function> or <function>strfmon()</function> style 
189 function (with the remaining arguments to the format function the same as 
190 they would have been for the unmodified string). 
191 See the GNU C documentation for details. 
192 </para>
193 <informalexample><programlisting>
194 gchar *g_dgettext (gchar *domain_name, gchar *msgid) G_GNUC_FORMAT (2);
195 </programlisting></informalexample>
196
197 @arg_idx: the index of the argument.
198
199
200 <!-- ##### MACRO G_GNUC_FUNCTION ##### -->
201 <para>
202 Expands to the GNU C <literal>__FUNCTION__</literal> variable if the 
203 compiler is GNU C, or "" if it isn't. The GNU C 
204 <literal>__FUNCTION__</literal> variable contains the name of the 
205 current function. See the GNU C documentation for details. 
206 </para>
207
208
209
210 <!-- ##### MACRO G_GNUC_PRETTY_FUNCTION ##### -->
211 <para>
212 Expands to the GNU C <literal>__PRETTY_FUNCTION__</literal> variable 
213 if the compiler is GNU C, or "" if it isn't.
214 The GNU C <literal>__PRETTY_FUNCTION__</literal> variable contains the 
215 name of the current function. For a C program this is the same as the 
216 <literal>__FUNCTION__</literal> variable but for C++ it also includes 
217 extra information such as the class and function prototype. See the 
218 GNU C documentation for details. 
219 </para>
220
221
222
223 <!-- ##### MACRO G_GNUC_NO_INSTRUMENT ##### -->
224 <para>
225 Expands to the GNU C no_instrument_function function attribute if 
226 the compiler is GNU C. Functions with this attribute will not be 
227 instrumented for profiling, when the compiler is called with the
228 <option>-finstrument-functions</option> option.
229 See the GNU C documentation for details. 
230 </para>
231
232
233
234 <!-- ##### MACRO G_STRLOC ##### -->
235 <para>
236 Expands to a string identifying the current code position. 
237 </para>
238
239
240
241 <!-- ##### MACRO G_GINT16_FORMAT ##### -->
242 <para>
243 This is the platform dependent conversion specifier for scanning and
244 printing values of type #gint16. It is a string literal, but doesn't
245 include the percent-sign, such that you can add precision and length
246 modifiers between percent-sign and conversion specifier.
247 </para>
248
249 <para>
250 <informalexample>
251 <programlisting>
252 gint16 in;
253 gint32 out;
254 sscanf ("42", "%" G_GINT16_FORMAT, &amp;in)
255 out = in * 1000;
256 g_print ("%" G_GINT32_FORMAT, out);
257 </programlisting>
258 </informalexample>
259 </para>
260
261
262
263 <!-- ##### MACRO G_GUINT16_FORMAT ##### -->
264 <para>
265 This is the platform dependent conversion specifier for scanning and
266 printing values of type #guint16. See also #G_GINT16_FORMAT.
267 </para>
268
269
270
271 <!-- ##### MACRO G_GINT32_FORMAT ##### -->
272 <para>
273 This is the platform dependent conversion specifier for scanning and
274 printing values of type #gint32. See also #G_GINT16_FORMAT.
275 </para>
276
277
278
279 <!-- ##### MACRO G_GUINT32_FORMAT ##### -->
280 <para>
281 This is the platform dependent conversion specifier for scanning and
282 printing values of type #guint32. See also #G_GINT16_FORMAT.
283 </para>
284
285
286
287 <!-- ##### MACRO G_GINT64_FORMAT ##### -->
288 <para>
289 This is the platform dependent conversion specifier for scanning and
290 printing values of type #gint64. See also #G_GINT16_FORMAT.
291 </para>
292
293 <note>
294 <para>
295 Some platforms do not support scanning and printing 64 bit integers,
296 even though the types are supported. On such platforms #G_GINT64_FORMAT
297 is not defined.
298 </para>
299 </note>
300
301
302
303 <!-- ##### MACRO G_GUINT64_FORMAT ##### -->
304 <para>
305 This is the platform dependent conversion specifier for scanning and
306 printing values of type #guint64. See also #G_GINT16_FORMAT.
307 </para>
308
309 <note>
310 <para>
311 Some platforms do not support scanning and printing 64 bit integers,
312 even though the types are supported. On such platforms #G_GUINT64_FORMAT
313 is not defined.
314 </para>
315 </note>
316
317
318