| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <title>Standard Macros</title> |
| <meta name="generator" content="DocBook XSL Stylesheets V1.75.2"> |
| <link rel="home" href="index.html" title="GLib Reference Manual"> |
| <link rel="up" href="glib-fundamentals.html" title="GLib Fundamentals"> |
| <link rel="prev" href="glib-Limits-of-Basic-Types.html" title="Limits of Basic Types"> |
| <link rel="next" href="glib-Type-Conversion-Macros.html" title="Type Conversion Macros"> |
| <meta name="generator" content="GTK-Doc V1.14 (XML mode)"> |
| <link rel="stylesheet" href="style.css" type="text/css"> |
| </head> |
| <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"> |
| <tr valign="middle"> |
| <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> |
| <td><a accesskey="u" href="glib-fundamentals.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td> |
| <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td> |
| <th width="100%" align="center">GLib Reference Manual</th> |
| <td><a accesskey="n" href="glib-Type-Conversion-Macros.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td> |
| </tr> |
| <tr><td colspan="5" class="shortcuts"> |
| <a href="#glib-Standard-Macros.synopsis" class="shortcut">Top</a> |
| | |
| <a href="#glib-Standard-Macros.description" class="shortcut">Description</a> |
| </td></tr> |
| </table> |
| <div class="refentry" title="Standard Macros"> |
| <a name="glib-Standard-Macros"></a><div class="titlepage"></div> |
| <div class="refnamediv"><table width="100%"><tr> |
| <td valign="top"> |
| <h2><span class="refentrytitle"><a name="glib-Standard-Macros.top_of_page"></a>Standard Macros</span></h2> |
| <p>Standard Macros — commonly-used macros.</p> |
| </td> |
| <td valign="top" align="right"></td> |
| </tr></table></div> |
| <div class="refsynopsisdiv" title="Synopsis"> |
| <a name="glib-Standard-Macros.synopsis"></a><h2>Synopsis</h2> |
| <pre class="synopsis"> |
| #include <glib.h> |
| |
| #define <a class="link" href="glib-Standard-Macros.html#G-OS-WIN32:CAPS" title="G_OS_WIN32">G_OS_WIN32</a> |
| #define <a class="link" href="glib-Standard-Macros.html#G-OS-BEOS:CAPS" title="G_OS_BEOS">G_OS_BEOS</a> |
| #define <a class="link" href="glib-Standard-Macros.html#G-OS-UNIX:CAPS" title="G_OS_UNIX">G_OS_UNIX</a> |
| |
| #define <a class="link" href="glib-Standard-Macros.html#G-DIR-SEPARATOR:CAPS" title="G_DIR_SEPARATOR">G_DIR_SEPARATOR</a> |
| #define <a class="link" href="glib-Standard-Macros.html#G-DIR-SEPARATOR-S:CAPS" title="G_DIR_SEPARATOR_S">G_DIR_SEPARATOR_S</a> |
| #define <a class="link" href="glib-Standard-Macros.html#G-IS-DIR-SEPARATOR:CAPS" title="G_IS_DIR_SEPARATOR()">G_IS_DIR_SEPARATOR</a> (c) |
| #define <a class="link" href="glib-Standard-Macros.html#G-SEARCHPATH-SEPARATOR:CAPS" title="G_SEARCHPATH_SEPARATOR">G_SEARCHPATH_SEPARATOR</a> |
| #define <a class="link" href="glib-Standard-Macros.html#G-SEARCHPATH-SEPARATOR-S:CAPS" title="G_SEARCHPATH_SEPARATOR_S">G_SEARCHPATH_SEPARATOR_S</a> |
| |
| #define <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE">TRUE</a> |
| #define <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE">FALSE</a> |
| |
| #define <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL">NULL</a> |
| |
| #define <a class="link" href="glib-Standard-Macros.html#MIN:CAPS" title="MIN()">MIN</a> (a, |
| b) |
| #define <a class="link" href="glib-Standard-Macros.html#MAX:CAPS" title="MAX()">MAX</a> (a, |
| b) |
| |
| #define <a class="link" href="glib-Standard-Macros.html#ABS:CAPS" title="ABS()">ABS</a> (a) |
| #define <a class="link" href="glib-Standard-Macros.html#CLAMP:CAPS" title="CLAMP()">CLAMP</a> (x, |
| low, |
| high) |
| |
| #define <a class="link" href="glib-Standard-Macros.html#G-STRUCT-MEMBER:CAPS" title="G_STRUCT_MEMBER()">G_STRUCT_MEMBER</a> (member_type, |
| struct_p, |
| struct_offset) |
| #define <a class="link" href="glib-Standard-Macros.html#G-STRUCT-MEMBER-P:CAPS" title="G_STRUCT_MEMBER_P()">G_STRUCT_MEMBER_P</a> (struct_p, |
| struct_offset) |
| #define <a class="link" href="glib-Standard-Macros.html#G-STRUCT-OFFSET:CAPS" title="G_STRUCT_OFFSET()">G_STRUCT_OFFSET</a> (struct_type, |
| member) |
| |
| #define <a class="link" href="glib-Standard-Macros.html#G-MEM-ALIGN:CAPS" title="G_MEM_ALIGN">G_MEM_ALIGN</a> |
| |
| #define <a class="link" href="glib-Standard-Macros.html#G-CONST-RETURN:CAPS" title="G_CONST_RETURN">G_CONST_RETURN</a> |
| </pre> |
| </div> |
| <div class="refsect1" title="Description"> |
| <a name="glib-Standard-Macros.description"></a><h2>Description</h2> |
| <p> |
| These macros provide a few commonly-used features. |
| </p> |
| </div> |
| <div class="refsect1" title="Details"> |
| <a name="glib-Standard-Macros.details"></a><h2>Details</h2> |
| <div class="refsect2" title="G_OS_WIN32"> |
| <a name="G-OS-WIN32:CAPS"></a><h3>G_OS_WIN32</h3> |
| <pre class="programlisting">#define G_OS_WIN32 |
| </pre> |
| <p> |
| This macro is defined only on Windows. So you can bracket |
| Windows-specific code in "#ifdef G_OS_WIN32". |
| </p> |
| </div> |
| <hr> |
| <div class="refsect2" title="G_OS_BEOS"> |
| <a name="G-OS-BEOS:CAPS"></a><h3>G_OS_BEOS</h3> |
| <pre class="programlisting">#define G_OS_BEOS |
| </pre> |
| <p> |
| This macro is defined only on BeOS. So you can bracket |
| BeOS-specific code in "#ifdef G_OS_BEOS". |
| </p> |
| </div> |
| <hr> |
| <div class="refsect2" title="G_OS_UNIX"> |
| <a name="G-OS-UNIX:CAPS"></a><h3>G_OS_UNIX</h3> |
| <pre class="programlisting">#define G_OS_UNIX |
| </pre> |
| <p> |
| This macro is defined only on UNIX. So you can bracket |
| UNIX-specific code in "#ifdef G_OS_UNIX". |
| </p> |
| </div> |
| <hr> |
| <div class="refsect2" title="G_DIR_SEPARATOR"> |
| <a name="G-DIR-SEPARATOR:CAPS"></a><h3>G_DIR_SEPARATOR</h3> |
| <pre class="programlisting">#define G_DIR_SEPARATOR</pre> |
| <p> |
| The directory separator character. |
| This is '/' on UNIX machines and '\' under Windows. |
| </p> |
| </div> |
| <hr> |
| <div class="refsect2" title="G_DIR_SEPARATOR_S"> |
| <a name="G-DIR-SEPARATOR-S:CAPS"></a><h3>G_DIR_SEPARATOR_S</h3> |
| <pre class="programlisting">#define G_DIR_SEPARATOR_S</pre> |
| <p> |
| The directory separator as a string. |
| This is "/" on UNIX machines and "\" under Windows. |
| </p> |
| </div> |
| <hr> |
| <div class="refsect2" title="G_IS_DIR_SEPARATOR()"> |
| <a name="G-IS-DIR-SEPARATOR:CAPS"></a><h3>G_IS_DIR_SEPARATOR()</h3> |
| <pre class="programlisting">#define G_IS_DIR_SEPARATOR(c)</pre> |
| <p> |
| Checks whether a character is a directory |
| separator. It returns <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> for '/' on UNIX |
| machines and for '\' or '/' under Windows. |
| </p> |
| <div class="variablelist"><table border="0"> |
| <col align="left" valign="top"> |
| <tbody><tr> |
| <td><p><span class="term"><em class="parameter"><code>c</code></em> :</span></p></td> |
| <td>a character |
| </td> |
| </tr></tbody> |
| </table></div> |
| <p class="since">Since 2.6</p> |
| </div> |
| <hr> |
| <div class="refsect2" title="G_SEARCHPATH_SEPARATOR"> |
| <a name="G-SEARCHPATH-SEPARATOR:CAPS"></a><h3>G_SEARCHPATH_SEPARATOR</h3> |
| <pre class="programlisting">#define G_SEARCHPATH_SEPARATOR</pre> |
| <p> |
| The search path separator character. |
| This is ':' on UNIX machines and ';' under Windows. |
| </p> |
| </div> |
| <hr> |
| <div class="refsect2" title="G_SEARCHPATH_SEPARATOR_S"> |
| <a name="G-SEARCHPATH-SEPARATOR-S:CAPS"></a><h3>G_SEARCHPATH_SEPARATOR_S</h3> |
| <pre class="programlisting">#define G_SEARCHPATH_SEPARATOR_S</pre> |
| <p> |
| The search path separator as a string. |
| This is ":" on UNIX machines and ";" under Windows. |
| </p> |
| </div> |
| <hr> |
| <div class="refsect2" title="TRUE"> |
| <a name="TRUE:CAPS"></a><h3>TRUE</h3> |
| <pre class="programlisting">#define TRUE (!FALSE) |
| </pre> |
| <p> |
| Defines the <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> value for the <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a> type. |
| </p> |
| </div> |
| <hr> |
| <div class="refsect2" title="FALSE"> |
| <a name="FALSE:CAPS"></a><h3>FALSE</h3> |
| <pre class="programlisting">#define FALSE (0) |
| </pre> |
| <p> |
| Defines the <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> value for the <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a> type. |
| </p> |
| </div> |
| <hr> |
| <div class="refsect2" title="NULL"> |
| <a name="NULL:CAPS"></a><h3>NULL</h3> |
| <pre class="programlisting">#define NULL</pre> |
| <p> |
| Defines the standard <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> pointer. |
| </p> |
| </div> |
| <hr> |
| <div class="refsect2" title="MIN()"> |
| <a name="MIN:CAPS"></a><h3>MIN()</h3> |
| <pre class="programlisting">#define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
| </pre> |
| <p> |
| Calculates the minimum of <em class="parameter"><code>a</code></em> and <em class="parameter"><code>b</code></em>. |
| </p> |
| <div class="variablelist"><table border="0"> |
| <col align="left" valign="top"> |
| <tbody> |
| <tr> |
| <td><p><span class="term"><em class="parameter"><code>a</code></em> :</span></p></td> |
| <td>a numeric value. |
| </td> |
| </tr> |
| <tr> |
| <td><p><span class="term"><em class="parameter"><code>b</code></em> :</span></p></td> |
| <td>a numeric value. |
| </td> |
| </tr> |
| <tr> |
| <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td> |
| <td>the minimum of <em class="parameter"><code>a</code></em> and <em class="parameter"><code>b</code></em>. |
| </td> |
| </tr> |
| </tbody> |
| </table></div> |
| </div> |
| <hr> |
| <div class="refsect2" title="MAX()"> |
| <a name="MAX:CAPS"></a><h3>MAX()</h3> |
| <pre class="programlisting">#define MAX(a, b) (((a) > (b)) ? (a) : (b)) |
| </pre> |
| <p> |
| Calculates the maximum of <em class="parameter"><code>a</code></em> and <em class="parameter"><code>b</code></em>. |
| </p> |
| <div class="variablelist"><table border="0"> |
| <col align="left" valign="top"> |
| <tbody> |
| <tr> |
| <td><p><span class="term"><em class="parameter"><code>a</code></em> :</span></p></td> |
| <td>a numeric value. |
| </td> |
| </tr> |
| <tr> |
| <td><p><span class="term"><em class="parameter"><code>b</code></em> :</span></p></td> |
| <td>a numeric value. |
| </td> |
| </tr> |
| <tr> |
| <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td> |
| <td>the maximum of <em class="parameter"><code>a</code></em> and <em class="parameter"><code>b</code></em>. |
| </td> |
| </tr> |
| </tbody> |
| </table></div> |
| </div> |
| <hr> |
| <div class="refsect2" title="ABS()"> |
| <a name="ABS:CAPS"></a><h3>ABS()</h3> |
| <pre class="programlisting">#define ABS(a) (((a) < 0) ? -(a) : (a)) |
| </pre> |
| <p> |
| Calculates the absolute value of <em class="parameter"><code>a</code></em>. |
| The absolute value is simply the number with any negative sign taken away. |
| </p> |
| <p> |
| For example, |
| </p> |
| <div class="itemizedlist"><ul class="itemizedlist" type="disc"> |
| <li class="listitem"><p> |
| ABS(-10) is 10. |
| </p></li> |
| <li class="listitem"><p> |
| ABS(10) is also 10. |
| </p></li> |
| </ul></div> |
| <p> |
| </p> |
| <div class="variablelist"><table border="0"> |
| <col align="left" valign="top"> |
| <tbody> |
| <tr> |
| <td><p><span class="term"><em class="parameter"><code>a</code></em> :</span></p></td> |
| <td>a numeric value. |
| </td> |
| </tr> |
| <tr> |
| <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td> |
| <td>the absolute value of <em class="parameter"><code>a</code></em>. |
| </td> |
| </tr> |
| </tbody> |
| </table></div> |
| </div> |
| <hr> |
| <div class="refsect2" title="CLAMP()"> |
| <a name="CLAMP:CAPS"></a><h3>CLAMP()</h3> |
| <pre class="programlisting">#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x))) |
| </pre> |
| <p> |
| 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>. If <em class="parameter"><code>low</code></em> is |
| greater than <em class="parameter"><code>high</code></em> the result is undefined. |
| </p> |
| <p> |
| For example, |
| </p> |
| <div class="itemizedlist"><ul class="itemizedlist" type="disc"> |
| <li class="listitem"><p> |
| CLAMP(5, 10, 15) is 10. |
| </p></li> |
| <li class="listitem"><p> |
| CLAMP(15, 5, 10) is 10. |
| </p></li> |
| <li class="listitem"><p> |
| CLAMP(20, 15, 25) is 20. |
| </p></li> |
| </ul></div> |
| <p> |
| </p> |
| <div class="variablelist"><table border="0"> |
| <col align="left" valign="top"> |
| <tbody> |
| <tr> |
| <td><p><span class="term"><em class="parameter"><code>x</code></em> :</span></p></td> |
| <td>the value to clamp. |
| </td> |
| </tr> |
| <tr> |
| <td><p><span class="term"><em class="parameter"><code>low</code></em> :</span></p></td> |
| <td>the minimum value allowed. |
| </td> |
| </tr> |
| <tr> |
| <td><p><span class="term"><em class="parameter"><code>high</code></em> :</span></p></td> |
| <td>the maximum value allowed. |
| </td> |
| </tr> |
| <tr> |
| <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td> |
| <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>. |
| </td> |
| </tr> |
| </tbody> |
| </table></div> |
| </div> |
| <hr> |
| <div class="refsect2" title="G_STRUCT_MEMBER()"> |
| <a name="G-STRUCT-MEMBER:CAPS"></a><h3>G_STRUCT_MEMBER()</h3> |
| <pre class="programlisting">#define G_STRUCT_MEMBER(member_type, struct_p, struct_offset)</pre> |
| <p> |
| Returns a member of a structure at a given offset, using the given type. |
| </p> |
| <div class="variablelist"><table border="0"> |
| <col align="left" valign="top"> |
| <tbody> |
| <tr> |
| <td><p><span class="term"><em class="parameter"><code>member_type</code></em> :</span></p></td> |
| <td>the type of the struct field. |
| </td> |
| </tr> |
| <tr> |
| <td><p><span class="term"><em class="parameter"><code>struct_p</code></em> :</span></p></td> |
| <td>a pointer to a struct. |
| </td> |
| </tr> |
| <tr> |
| <td><p><span class="term"><em class="parameter"><code>struct_offset</code></em> :</span></p></td> |
| <td>the offset of the field from the start of the struct, in bytes. |
| </td> |
| </tr> |
| <tr> |
| <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td> |
| <td>the struct member. |
| </td> |
| </tr> |
| </tbody> |
| </table></div> |
| </div> |
| <hr> |
| <div class="refsect2" title="G_STRUCT_MEMBER_P()"> |
| <a name="G-STRUCT-MEMBER-P:CAPS"></a><h3>G_STRUCT_MEMBER_P()</h3> |
| <pre class="programlisting">#define G_STRUCT_MEMBER_P(struct_p, struct_offset)</pre> |
| <p> |
| Returns an untyped pointer to a given offset of a struct. |
| </p> |
| <div class="variablelist"><table border="0"> |
| <col align="left" valign="top"> |
| <tbody> |
| <tr> |
| <td><p><span class="term"><em class="parameter"><code>struct_p</code></em> :</span></p></td> |
| <td>a pointer to a struct. |
| </td> |
| </tr> |
| <tr> |
| <td><p><span class="term"><em class="parameter"><code>struct_offset</code></em> :</span></p></td> |
| <td>the offset from the start of the struct, in bytes. |
| </td> |
| </tr> |
| <tr> |
| <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td> |
| <td>an untyped pointer to <em class="parameter"><code>struct_p</code></em> plus <em class="parameter"><code>struct_offset</code></em> bytes. |
| </td> |
| </tr> |
| </tbody> |
| </table></div> |
| </div> |
| <hr> |
| <div class="refsect2" title="G_STRUCT_OFFSET()"> |
| <a name="G-STRUCT-OFFSET:CAPS"></a><h3>G_STRUCT_OFFSET()</h3> |
| <pre class="programlisting">#define G_STRUCT_OFFSET(struct_type, member)</pre> |
| <p> |
| Returns the offset, in bytes, of a member of a struct. |
| </p> |
| <div class="variablelist"><table border="0"> |
| <col align="left" valign="top"> |
| <tbody> |
| <tr> |
| <td><p><span class="term"><em class="parameter"><code>struct_type</code></em> :</span></p></td> |
| <td>a structure type, e.g. <span class="structname">GtkWidget</span>. |
| </td> |
| </tr> |
| <tr> |
| <td><p><span class="term"><em class="parameter"><code>member</code></em> :</span></p></td> |
| <td>a field in the structure, e.g. <em class="structfield"><code>window</code></em>. |
| </td> |
| </tr> |
| <tr> |
| <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td> |
| <td>the offset of <em class="parameter"><code>member</code></em> from the start of <em class="parameter"><code>struct_type</code></em>. |
| </td> |
| </tr> |
| </tbody> |
| </table></div> |
| </div> |
| <hr> |
| <div class="refsect2" title="G_MEM_ALIGN"> |
| <a name="G-MEM-ALIGN:CAPS"></a><h3>G_MEM_ALIGN</h3> |
| <pre class="programlisting">#define G_MEM_ALIGN</pre> |
| <p> |
| Indicates the number of bytes to which memory will be aligned on the |
| current platform. |
| </p> |
| </div> |
| <hr> |
| <div class="refsect2" title="G_CONST_RETURN"> |
| <a name="G-CONST-RETURN:CAPS"></a><h3>G_CONST_RETURN</h3> |
| <pre class="programlisting">#define G_CONST_RETURN</pre> |
| <p> |
| If <code class="literal">G_DISABLE_CONST_RETURNS</code> is defined, this macro expands to nothing. |
| By default, the macro expands to <code class="literal">const</code>. The macro |
| should be used in place of <code class="literal">const</code> for functions that |
| return a value that should not be modified. The purpose of this macro is |
| to allow us to turn on <code class="literal">const</code> for returned constant |
| strings by default, while allowing programmers who find that annoying to |
| turn it off. This macro should only be used for return values and for |
| <span class="emphasis"><em>out</em></span> parameters, it doesn't make sense for |
| <span class="emphasis"><em>in</em></span> parameters. |
| </p> |
| </div> |
| </div> |
| </div> |
| <div class="footer"> |
| <hr> |
| Generated by GTK-Doc V1.14</div> |
| </body> |
| </html> |