glib/tmpl/macros.sgml, glib/tmpl/macros_misc.sgml,
[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_CONST ##### -->
102 <para>
103 Expands to the GNU C const function attribute if the compiler is GNU C.
104 This enables optimization of the function.
105 See the GNU C documentation for details. 
106 </para>
107
108
109
110 <!-- ##### MACRO G_GNUC_NORETURN ##### -->
111 <para>
112 Expands to the GNU C noreturn function attribute if the compiler is GNU C.
113 It is used for declaring functions which never return.
114 It enables optimization of the function, and avoids possible compiler
115 warnings. See the GNU C documentation for details. 
116 </para>
117
118
119
120 <!-- ##### MACRO G_GNUC_UNUSED ##### -->
121 <para>
122 Expands to the GNU C unused function attribute if the compiler is GNU C.
123 It is used for declaring functions which may never be used.
124 It avoids possible compiler warnings. See the GNU C documentation for details. 
125 </para>
126
127
128
129 <!-- ##### MACRO G_GNUC_PURE ##### -->
130 <para>
131 Expands to the GNU C pure function attribute if the compiler is GNU C.
132 See the GNU C documentation for details. 
133
134 FIXME: Explain what pure functions are.
135 </para>
136
137
138
139 <!-- ##### MACRO G_GNUC_PRINTF ##### -->
140 <para>
141 Expands to the GNU C format function attribute if the compiler is GNU C.
142 This is used for declaring functions which take a variable number of
143 arguments, with the same syntax as <function>printf()</function>.
144 It allows the compiler to type-check the arguments passed to the function.
145 See the GNU C documentation for details. 
146 </para>
147
148 @format_idx: the index of the argument corresponding to the format string.
149 (The arguments are numbered from 1).
150 @arg_idx: the index of the first of the format arguments.
151
152
153 <!-- ##### MACRO G_GNUC_SCANF ##### -->
154 <para>
155 Expands to the GNU C format function attribute if the compiler is GNU C.
156 This is used for declaring functions which take a variable number of
157 arguments, with the same syntax as <function>scanf()</function>.
158 It allows the compiler to type-check the arguments passed to the function.
159 See the GNU C documentation for details. 
160 </para>
161
162 @format_idx: the index of the argument corresponding to the format string.
163 (The arguments are numbered from 1).
164 @arg_idx: the index of the first of the format arguments.
165
166
167 <!-- ##### MACRO G_GNUC_FORMAT ##### -->
168 <para>
169 Expands to the GNU C format_arg function attribute if the compiler is GNU C.
170 This is used for declaring functions which take a variable number of
171 parameters, like <function>printf()</function> and
172 <function>scanf()</function>. See the GNU C documentation for details. 
173
174 FIXME: I can't find this in my GNU C documentation. Take out?
175 </para>
176
177 @arg_idx: the index of the argument.
178
179
180 <!-- ##### MACRO G_GNUC_FUNCTION ##### -->
181 <para>
182 Expands to the GNU C <literal>__FUNCTION__</literal> variable if the 
183 compiler is GNU C, or "" if it isn't. The GNU C 
184 <literal>__FUNCTION__</literal> variable contains the name of the 
185 current function. See the GNU C documentation for details. 
186 </para>
187
188
189
190 <!-- ##### MACRO G_GNUC_PRETTY_FUNCTION ##### -->
191 <para>
192 Expands to the GNU C <literal>__PRETTY_FUNCTION__</literal> variable 
193 if the compiler is GNU C, or "" if it isn't.
194 The GNU C <literal>__PRETTY_FUNCTION__</literal> variable contains the 
195 name of the current function. For a C program this is the same as the 
196 <literal>__FUNCTION__</literal> variable but for C++ it also includes 
197 extra information such as the class and function prototype. See the 
198 GNU C documentation for details. 
199 </para>
200
201
202
203 <!-- ##### MACRO G_GNUC_NO_INSTRUMENT ##### -->
204 <para>
205 Expands to the GNU C no_instrument_function function attribute if 
206 the compiler is GNU C.
207 See the GNU C documentation for details. 
208
209 FIXME: Explain no_instrument_function.
210 </para>
211
212
213
214 <!-- ##### MACRO G_STRLOC ##### -->
215 <para>
216 Expands to a string identifying the current code position. 
217 </para>
218
219
220
221 <!-- ##### MACRO G_GINT16_FORMAT ##### -->
222 <para>
223 This is the platform dependent conversion specifier for scanning and
224 printing values of type #gint16. It is a string literal, but doesn't
225 include the percent-sign, such that you can add precision and length
226 modifiers between percent-sign and conversion specifier.
227 </para>
228
229 <para>
230 <informalexample>
231 <programlisting>
232 gint16 in;
233 gint32 out;
234 sscanf ("42", "%" G_GINT16_FORMAT, &amp;in)
235 out = in * 1000;
236 g_print ("%" G_GINT32_FORMAT, out);
237 </programlisting>
238 </informalexample>
239 </para>
240
241
242
243 <!-- ##### MACRO G_GUINT16_FORMAT ##### -->
244 <para>
245 This is the platform dependent conversion specifier for scanning and
246 printing values of type #guint16. See also #G_GINT16_FORMAT.
247 </para>
248
249
250
251 <!-- ##### MACRO G_GINT32_FORMAT ##### -->
252 <para>
253 This is the platform dependent conversion specifier for scanning and
254 printing values of type #gint32. See also #G_GINT16_FORMAT.
255 </para>
256
257
258
259 <!-- ##### MACRO G_GUINT32_FORMAT ##### -->
260 <para>
261 This is the platform dependent conversion specifier for scanning and
262 printing values of type #guint32. See also #G_GINT16_FORMAT.
263 </para>
264
265
266
267 <!-- ##### MACRO G_GINT64_FORMAT ##### -->
268 <para>
269 This is the platform dependent conversion specifier for scanning and
270 printing values of type #gint64. See also #G_GINT16_FORMAT.
271 </para>
272
273 <note>
274 <para>
275 Some platforms do not support scanning and printing 64 bit integers,
276 even though the types are supported. On such platforms #G_GINT64_FORMAT
277 is not defined.
278 </para>
279 </note>
280
281
282
283 <!-- ##### MACRO G_GUINT64_FORMAT ##### -->
284 <para>
285 This is the platform dependent conversion specifier for scanning and
286 printing values of type #guint64. See also #G_GINT16_FORMAT.
287 </para>
288
289 <note>
290 <para>
291 Some platforms do not support scanning and printing 64 bit integers,
292 even though the types are supported. On such platforms #G_GUINT64_FORMAT
293 is not defined.
294 </para>
295 </note>
296
297
298