1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
5
<title>Standard Macros</title>
6
<meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
7
<link rel="start" href="index.html" title="GLib Reference Manual">
8
<link rel="up" href="glib-fundamentals.html" title="GLib Fundamentals">
9
<link rel="prev" href="glib-Limits-of-Basic-Types.html" title="Limits of Basic Types">
10
<link rel="next" href="glib-Type-Conversion-Macros.html" title="Type Conversion Macros">
11
<meta name="generator" content="GTK-Doc V1.7 (XML mode)">
12
<link rel="stylesheet" href="style.css" type="text/css">
13
<link rel="chapter" href="glib.html" title="GLib Overview">
14
<link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals">
15
<link rel="chapter" href="glib-core.html" title="GLib Core Application Support">
16
<link rel="chapter" href="glib-utilities.html" title="GLib Utilities">
17
<link rel="chapter" href="glib-data-types.html" title="GLib Data Types">
18
<link rel="chapter" href="tools.html" title="GLib Tools">
19
<link rel="index" href="ix01.html" title="Index">
20
<link rel="index" href="ix02.html" title="Index of deprecated symbols">
21
<link rel="index" href="ix03.html" title="Index of new symbols in 2.2">
22
<link rel="index" href="ix04.html" title="Index of new symbols in 2.4">
23
<link rel="index" href="ix05.html" title="Index of new symbols in 2.6">
24
<link rel="index" href="ix06.html" title="Index of new symbols in 2.8">
25
<link rel="index" href="ix07.html" title="Index of new symbols in 2.10">
26
<link rel="index" href="ix08.html" title="Index of new symbols in 2.12">
28
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
29
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
31
<td><a accesskey="p" href="glib-Limits-of-Basic-Types.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
32
<td><a accesskey="u" href="glib-fundamentals.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
33
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
34
<th width="100%" align="center">GLib Reference Manual</th>
35
<td><a accesskey="n" href="glib-Type-Conversion-Macros.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
37
<tr><td colspan="5" class="shortcuts"><nobr><a href="#id2697165" class="shortcut">Top</a>
39
<a href="#id2697347" class="shortcut">Description</a></nobr></td></tr>
41
<div class="refentry" lang="en">
42
<a name="glib-Standard-Macros"></a><div class="titlepage"></div>
43
<div class="refnamediv"><table width="100%"><tr>
46
<a name="id2697165"></a><span class="refentrytitle">Standard Macros</span>
48
<p>Standard Macros — commonly-used macros.</p>
50
<td valign="top" align="right"></td>
52
<div class="refsynopsisdiv">
54
<pre class="synopsis">
56
#include <glib.h>
60
#define <a href="glib-Standard-Macros.html#G-OS-WIN32:CAPS">G_OS_WIN32</a>
61
#define <a href="glib-Standard-Macros.html#G-OS-BEOS:CAPS">G_OS_BEOS</a>
62
#define <a href="glib-Standard-Macros.html#G-OS-UNIX:CAPS">G_OS_UNIX</a>
64
#define <a href="glib-Standard-Macros.html#G-DIR-SEPARATOR:CAPS">G_DIR_SEPARATOR</a>
65
#define <a href="glib-Standard-Macros.html#G-DIR-SEPARATOR-S:CAPS">G_DIR_SEPARATOR_S</a>
66
#define <a href="glib-Standard-Macros.html#G-IS-DIR-SEPARATOR:CAPS">G_IS_DIR_SEPARATOR</a> (c)
67
#define <a href="glib-Standard-Macros.html#G-SEARCHPATH-SEPARATOR:CAPS">G_SEARCHPATH_SEPARATOR</a>
68
#define <a href="glib-Standard-Macros.html#G-SEARCHPATH-SEPARATOR-S:CAPS">G_SEARCHPATH_SEPARATOR_S</a>
70
#define <a href="glib-Standard-Macros.html#TRUE:CAPS">TRUE</a>
71
#define <a href="glib-Standard-Macros.html#FALSE:CAPS">FALSE</a>
73
#define <a href="glib-Standard-Macros.html#NULL:CAPS">NULL</a>
75
#define <a href="glib-Standard-Macros.html#MIN:CAPS">MIN</a> (a, b)
76
#define <a href="glib-Standard-Macros.html#MAX:CAPS">MAX</a> (a, b)
78
#define <a href="glib-Standard-Macros.html#ABS:CAPS">ABS</a> (a)
79
#define <a href="glib-Standard-Macros.html#CLAMP:CAPS">CLAMP</a> (x, low, high)
81
#define <a href="glib-Standard-Macros.html#G-STRUCT-MEMBER:CAPS">G_STRUCT_MEMBER</a> (member_type, struct_p, struct_offset)
82
#define <a href="glib-Standard-Macros.html#G-STRUCT-MEMBER-P:CAPS">G_STRUCT_MEMBER_P</a> (struct_p, struct_offset)
83
#define <a href="glib-Standard-Macros.html#G-STRUCT-OFFSET:CAPS">G_STRUCT_OFFSET</a> (struct_type, member)
85
#define <a href="glib-Standard-Macros.html#G-MEM-ALIGN:CAPS">G_MEM_ALIGN</a>
87
#define <a href="glib-Standard-Macros.html#G-CONST-RETURN:CAPS">G_CONST_RETURN</a>
90
<div class="refsect1" lang="en">
91
<a name="id2697347"></a><h2>Description</h2>
93
These macros provide a few commonly-used features.
96
<div class="refsect1" lang="en">
97
<a name="id2697362"></a><h2>Details</h2>
98
<div class="refsect2" lang="en">
99
<a name="id2697373"></a><h3>
100
<a name="G-OS-WIN32:CAPS"></a>G_OS_WIN32</h3>
101
<a class="indexterm" name="id2697385"></a><pre class="programlisting">#define G_OS_WIN32
104
This macro is defined only on Windows. So you can bracket
105
Windows-specific code in "#ifdef G_OS_WIN32".
109
<div class="refsect2" lang="en">
110
<a name="id2697408"></a><h3>
111
<a name="G-OS-BEOS:CAPS"></a>G_OS_BEOS</h3>
112
<a class="indexterm" name="id2697415"></a><pre class="programlisting">#define G_OS_BEOS
115
This macro is defined only on BeOS. So you can bracket
116
BeOS-specific code in "#ifdef G_OS_BEOS".
120
<div class="refsect2" lang="en">
121
<a name="id2697428"></a><h3>
122
<a name="G-OS-UNIX:CAPS"></a>G_OS_UNIX</h3>
123
<a class="indexterm" name="id2697444"></a><pre class="programlisting">#define G_OS_UNIX
126
This macro is defined only on UNIX. So you can bracket
127
UNIX-specific code in "#ifdef G_OS_UNIX".
131
<div class="refsect2" lang="en">
132
<a name="id2697461"></a><h3>
133
<a name="G-DIR-SEPARATOR:CAPS"></a>G_DIR_SEPARATOR</h3>
134
<a class="indexterm" name="id2697477"></a><pre class="programlisting">#define G_DIR_SEPARATOR</pre>
136
The directory separator character.
137
This is '/' on UNIX machines and '\' under Windows.
141
<div class="refsect2" lang="en">
142
<a name="id2697494"></a><h3>
143
<a name="G-DIR-SEPARATOR-S:CAPS"></a>G_DIR_SEPARATOR_S</h3>
144
<a class="indexterm" name="id2697506"></a><pre class="programlisting">#define G_DIR_SEPARATOR_S</pre>
146
The directory separator as a string.
147
This is "/" on UNIX machines and "\" under Windows.
151
<div class="refsect2" lang="en">
152
<a name="id2697522"></a><h3>
153
<a name="G-IS-DIR-SEPARATOR:CAPS"></a>G_IS_DIR_SEPARATOR()</h3>
154
<a class="indexterm" name="id2697537"></a><pre class="programlisting">#define G_IS_DIR_SEPARATOR(c)</pre>
156
Checks whether a character is a directory
157
separator. It returns <a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> for '/' on UNIX
158
machines and for '\' or '/' under Windows.
160
<div class="variablelist"><table border="0">
161
<col align="left" valign="top">
163
<td><span class="term"><em class="parameter"><code>c</code></em> :</span></td>
168
<p class="since">Since 2.6
174
<div class="refsect2" lang="en">
175
<a name="id2697590"></a><h3>
176
<a name="G-SEARCHPATH-SEPARATOR:CAPS"></a>G_SEARCHPATH_SEPARATOR</h3>
177
<a class="indexterm" name="id2697603"></a><pre class="programlisting">#define G_SEARCHPATH_SEPARATOR</pre>
179
The search path separator character.
180
This is ':' on UNIX machines and ';' under Windows.
184
<div class="refsect2" lang="en">
185
<a name="id2697619"></a><h3>
186
<a name="G-SEARCHPATH-SEPARATOR-S:CAPS"></a>G_SEARCHPATH_SEPARATOR_S</h3>
187
<a class="indexterm" name="id2697634"></a><pre class="programlisting">#define G_SEARCHPATH_SEPARATOR_S</pre>
189
The search path separator as a string.
190
This is ":" on UNIX machines and ";" under Windows.
194
<div class="refsect2" lang="en">
195
<a name="id2697651"></a><h3>
196
<a name="TRUE:CAPS"></a>TRUE</h3>
197
<a class="indexterm" name="id2697663"></a><pre class="programlisting">#define TRUE (!FALSE)
200
Defines the <a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> value for the <a href="glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a> type.
204
<div class="refsect2" lang="en">
205
<a name="id2697697"></a><h3>
206
<a name="FALSE:CAPS"></a>FALSE</h3>
207
<a class="indexterm" name="id2697709"></a><pre class="programlisting">#define FALSE (0)
210
Defines the <a href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> value for the <a href="glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a> type.
214
<div class="refsect2" lang="en">
215
<a name="id2697743"></a><h3>
216
<a name="NULL:CAPS"></a>NULL</h3>
217
<a class="indexterm" name="id2697755"></a><pre class="programlisting">#define NULL</pre>
219
Defines the standard <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> pointer.
223
<div class="refsect2" lang="en">
224
<a name="id2697781"></a><h3>
225
<a name="MIN:CAPS"></a>MIN()</h3>
226
<a class="indexterm" name="id2697794"></a><pre class="programlisting">#define MIN(a, b) (((a) < (b)) ? (a) : (b))
229
Calculates the minimum of <em class="parameter"><code>a</code></em> and <em class="parameter"><code>b</code></em>.
231
<div class="variablelist"><table border="0">
232
<col align="left" valign="top">
235
<td><span class="term"><em class="parameter"><code>a</code></em> :</span></td>
240
<td><span class="term"><em class="parameter"><code>b</code></em> :</span></td>
245
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
246
<td>the minimum of <em class="parameter"><code>a</code></em> and <em class="parameter"><code>b</code></em>.
255
<div class="refsect2" lang="en">
256
<a name="id2697874"></a><h3>
257
<a name="MAX:CAPS"></a>MAX()</h3>
258
<a class="indexterm" name="id2697886"></a><pre class="programlisting">#define MAX(a, b) (((a) > (b)) ? (a) : (b))
261
Calculates the maximum of <em class="parameter"><code>a</code></em> and <em class="parameter"><code>b</code></em>.
263
<div class="variablelist"><table border="0">
264
<col align="left" valign="top">
267
<td><span class="term"><em class="parameter"><code>a</code></em> :</span></td>
272
<td><span class="term"><em class="parameter"><code>b</code></em> :</span></td>
277
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
278
<td>the maximum of <em class="parameter"><code>a</code></em> and <em class="parameter"><code>b</code></em>.
287
<div class="refsect2" lang="en">
288
<a name="id2697966"></a><h3>
289
<a name="ABS:CAPS"></a>ABS()</h3>
290
<a class="indexterm" name="id2697978"></a><pre class="programlisting">#define ABS(a) (((a) < 0) ? -(a) : (a))
293
Calculates the absolute value of <em class="parameter"><code>a</code></em>.
294
The absolute value is simply the number with any negative sign taken away.
299
<div class="itemizedlist"><ul type="disc">
309
<div class="variablelist"><table border="0">
310
<col align="left" valign="top">
313
<td><span class="term"><em class="parameter"><code>a</code></em> :</span></td>
318
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
319
<td>the absolute value of <em class="parameter"><code>a</code></em>.
328
<div class="refsect2" lang="en">
329
<a name="id2698052"></a><h3>
330
<a name="CLAMP:CAPS"></a>CLAMP()</h3>
331
<a class="indexterm" name="id2698064"></a><pre class="programlisting">#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
334
Ensures that <em class="parameter"><code>x</code></em> is between the limits set by <em class="parameter"><code>low</code></em> and <em class="parameter"><code>high</code></em>.
339
<div class="itemizedlist"><ul type="disc">
341
CLAMP(5, 10, 15) is 10.
344
CLAMP(15, 5, 10) is 10.
347
CLAMP(20, 15, 25) is 20.
352
<div class="variablelist"><table border="0">
353
<col align="left" valign="top">
356
<td><span class="term"><em class="parameter"><code>x</code></em> :</span></td>
357
<td>the value to clamp.
361
<td><span class="term"><em class="parameter"><code>low</code></em> :</span></td>
362
<td>the minimum value allowed.
366
<td><span class="term"><em class="parameter"><code>high</code></em> :</span></td>
367
<td>the maximum value allowed.
371
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
372
<td>the value of <em class="parameter"><code>x</code></em> clamped to the range between <em class="parameter"><code>low</code></em> and <em class="parameter"><code>high</code></em>.
381
<div class="refsect2" lang="en">
382
<a name="id2698195"></a><h3>
383
<a name="G-STRUCT-MEMBER:CAPS"></a>G_STRUCT_MEMBER()</h3>
384
<a class="indexterm" name="id2698208"></a><pre class="programlisting">#define G_STRUCT_MEMBER(member_type, struct_p, struct_offset)</pre>
386
Returns a member of a structure at a given offset, using the given type.
388
<div class="variablelist"><table border="0">
389
<col align="left" valign="top">
392
<td><span class="term"><em class="parameter"><code>member_type</code></em> :</span></td>
393
<td>the type of the struct field.
397
<td><span class="term"><em class="parameter"><code>struct_p</code></em> :</span></td>
398
<td>a pointer to a struct.
402
<td><span class="term"><em class="parameter"><code>struct_offset</code></em> :</span></td>
403
<td>the offset of the field from the start of the struct, in bytes.
407
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
408
<td>the struct member.
417
<div class="refsect2" lang="en">
418
<a name="id2698283"></a><h3>
419
<a name="G-STRUCT-MEMBER-P:CAPS"></a>G_STRUCT_MEMBER_P()</h3>
420
<a class="indexterm" name="id2698296"></a><pre class="programlisting">#define G_STRUCT_MEMBER_P(struct_p, struct_offset)</pre>
422
Returns an untyped pointer to a given offset of a struct.
424
<div class="variablelist"><table border="0">
425
<col align="left" valign="top">
428
<td><span class="term"><em class="parameter"><code>struct_p</code></em> :</span></td>
429
<td>a pointer to a struct.
433
<td><span class="term"><em class="parameter"><code>struct_offset</code></em> :</span></td>
434
<td>the offset from the start of the struct, in bytes.
438
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
439
<td>an untyped pointer to <em class="parameter"><code>struct_p</code></em> plus <em class="parameter"><code>struct_offset</code></em> bytes.
448
<div class="refsect2" lang="en">
449
<a name="id2698369"></a><h3>
450
<a name="G-STRUCT-OFFSET:CAPS"></a>G_STRUCT_OFFSET()</h3>
451
<a class="indexterm" name="id2698382"></a><pre class="programlisting">#define G_STRUCT_OFFSET(struct_type, member)</pre>
453
Returns the offset, in bytes, of a member of a struct.
455
<div class="variablelist"><table border="0">
456
<col align="left" valign="top">
459
<td><span class="term"><em class="parameter"><code>struct_type</code></em> :</span></td>
460
<td>a structure type, e.g. <span class="structname">GtkWidget</span>.
464
<td><span class="term"><em class="parameter"><code>member</code></em> :</span></td>
465
<td>a field in the structure, e.g. <em class="structfield"><code>window</code></em>.
469
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
470
<td>the offset of <em class="parameter"><code>member</code></em> from the start of <em class="parameter"><code>struct_type</code></em>.
479
<div class="refsect2" lang="en">
480
<a name="id2698460"></a><h3>
481
<a name="G-MEM-ALIGN:CAPS"></a>G_MEM_ALIGN</h3>
482
<a class="indexterm" name="id2698473"></a><pre class="programlisting">#define G_MEM_ALIGN</pre>
484
Indicates the number of bytes to which memory will be aligned on the
489
<div class="refsect2" lang="en">
490
<a name="id2698489"></a><h3>
491
<a name="G-CONST-RETURN:CAPS"></a>G_CONST_RETURN</h3>
492
<a class="indexterm" name="id2698502"></a><pre class="programlisting">#define G_CONST_RETURN</pre>
494
If <code class="literal">G_DISABLE_CONST_RETURNS</code> is defined, this macro expands to nothing.
495
By default, the macro expands to <code class="literal">const</code>. The macro
496
should be used in place of <code class="literal">const</code> for functions that
497
return a value that should not be modified. The purpose of this macro is
498
to allow us to turn on <code class="literal">const</code> for returned constant
499
strings by default, while allowing programmers who find that annoying to
500
turn it off. This macro should only be used for return values and for
501
<span class="emphasis"><em>out</em></span> parameters, it doesn't make sense for
502
<span class="emphasis"><em>in</em></span> parameters.