📄 glib-standard-macros.html
字号:
<a class="indexterm" name="id2830686"></a><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" lang="en"><a name="id2830766"></a><h3><a name="ABS:CAPS"></a>ABS()</h3><a class="indexterm" name="id2830778"></a><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 type="disc"><li><p>ABS(-10) is 10.</p></li><li><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" lang="en"><a name="id2830851"></a><h3><a name="CLAMP:CAPS"></a>CLAMP()</h3><a class="indexterm" name="id2830863"></a><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> isgreater than <em class="parameter"><code>high</code></em> the result is undefined.</p><p>For example,</p><div class="itemizedlist"><ul type="disc"><li><p>CLAMP(5, 10, 15) is 10.</p></li><li><p>CLAMP(15, 5, 10) is 10.</p></li><li><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" lang="en"><a name="id2831007"></a><h3><a name="G-STRUCT-MEMBER:CAPS"></a>G_STRUCT_MEMBER()</h3><a class="indexterm" name="id2831020"></a><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" lang="en"><a name="id2831095"></a><h3><a name="G-STRUCT-MEMBER-P:CAPS"></a>G_STRUCT_MEMBER_P()</h3><a class="indexterm" name="id2831108"></a><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" lang="en"><a name="id2831180"></a><h3><a name="G-STRUCT-OFFSET:CAPS"></a>G_STRUCT_OFFSET()</h3><a class="indexterm" name="id2831193"></a><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" lang="en"><a name="id2831272"></a><h3><a name="G-MEM-ALIGN:CAPS"></a>G_MEM_ALIGN</h3><a class="indexterm" name="id2831284"></a><pre class="programlisting">#define G_MEM_ALIGN</pre><p>Indicates the number of bytes to which memory will be aligned on thecurrent platform.</p></div><hr><div class="refsect2" lang="en"><a name="id2831301"></a><h3><a name="G-CONST-RETURN:CAPS"></a>G_CONST_RETURN</h3><a class="indexterm" name="id2831313"></a><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 class="refsect1" lang="en"><a name="id2831376"></a><div class="refsect2" lang="en"><a name="id2831377"></a></div><hr><div class="refsect2" lang="en"><a name="id2831378"></a></div></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -