📄 glib-miscellaneous-macros.html
字号:
<hr><div class="refsect2" lang="en"><a name="id2839143"></a><h3><a name="G-GNUC-MALLOC:CAPS"></a>G_GNUC_MALLOC</h3><a class="indexterm" name="id2839153"></a><pre class="programlisting">#define G_GNUC_MALLOC</pre><p>Expands to the GNU C <code class="literal">malloc</code> function attribute if the compiler is <span><strong class="command">gcc</strong></span>. Declaring a function as malloc enables better optimization of the function. A function can have the malloc attribute if it returns a pointer which is guaranteedto not alias with any other pointer when the function returns (in practice, this means newly allocated memory). See the GNU C documentation for details. </p><p>Since 2.6</p></div><hr><div class="refsect2" lang="en"><a name="id2839191"></a><h3><a name="G-GNUC-DEPRECATED:CAPS"></a>G_GNUC_DEPRECATED</h3><a class="indexterm" name="id2839203"></a><pre class="programlisting">#define G_GNUC_DEPRECATED</pre><p>Expands to the GNU C <code class="literal">deprecated</code> attribute if the compiler is <span><strong class="command">gcc</strong></span>.It can be used to mark typedefs, variables and functions as deprecated. When called with the <code class="option">-Wdeprecated</code> option, the compiler will generate warnings when deprecated interfaces are used.See the GNU C documentation for details. </p><p>Since 2.2</p></div><hr><div class="refsect2" lang="en"><a name="id2839242"></a><h3><a name="G-GNUC-NORETURN:CAPS"></a>G_GNUC_NORETURN</h3><a class="indexterm" name="id2839253"></a><pre class="programlisting">#define G_GNUC_NORETURN</pre><p>Expands to the GNU C <code class="literal">noreturn</code> function attribute if the compiler is <span><strong class="command">gcc</strong></span>. It is used for declaring functions which never return.It enables optimization of the function, and avoids possible compilerwarnings. See the GNU C documentation for details. </p></div><hr><div class="refsect2" lang="en"><a name="id2839284"></a><h3><a name="G-GNUC-UNUSED:CAPS"></a>G_GNUC_UNUSED</h3><a class="indexterm" name="id2839294"></a><pre class="programlisting">#define G_GNUC_UNUSED</pre><p>Expands to the GNU C <code class="literal">unused</code> function attribute if the compiler is <span><strong class="command">gcc</strong></span>. It is used for declaring functions which may never be used.It avoids possible compiler warnings. See the GNU C documentation for details. </p></div><hr><div class="refsect2" lang="en"><a name="id2839324"></a><h3><a name="G-GNUC-PRINTF:CAPS"></a>G_GNUC_PRINTF()</h3><a class="indexterm" name="id2839335"></a><pre class="programlisting">#define G_GNUC_PRINTF( format_idx, arg_idx )</pre><p>Expands to the GNU C <code class="literal">format</code> function attribute if the compiler is <span><strong class="command">gcc</strong></span>. This is used for declaring functions which take a variable number ofarguments, with the same syntax as <code class="function"><code class="function">printf()</code></code>.It allows the compiler to type-check the arguments passed to the function.See the GNU C documentation for details. </p><div class="informalexample"><pre class="programlisting">gint g_snprintf (gchar *string, gulong n, gchar const *format, ...) G_GNUC_PRINTF (3, 4);</pre></div><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>format_idx</code></em> :</span></td><td>the index of the argument corresponding to the format string.(The arguments are numbered from 1).</td></tr><tr><td><span class="term"><em class="parameter"><code>arg_idx</code></em> :</span></td><td>the index of the first of the format arguments.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2839425"></a><h3><a name="G-GNUC-SCANF:CAPS"></a>G_GNUC_SCANF()</h3><a class="indexterm" name="id2839435"></a><pre class="programlisting">#define G_GNUC_SCANF( format_idx, arg_idx )</pre><p>Expands to the GNU C <code class="literal">format</code> function attribute if the compiler is <span><strong class="command">gcc</strong></span>.This is used for declaring functions which take a variable number ofarguments, with the same syntax as <code class="function"><code class="function">scanf()</code></code>.It allows the compiler to type-check the arguments passed to the function.See the GNU C documentation for details. </p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>format_idx</code></em> :</span></td><td>the index of the argument corresponding to the format string.(The arguments are numbered from 1).</td></tr><tr><td><span class="term"><em class="parameter"><code>arg_idx</code></em> :</span></td><td>the index of the first of the format arguments.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2839516"></a><h3><a name="G-GNUC-FORMAT:CAPS"></a>G_GNUC_FORMAT()</h3><a class="indexterm" name="id2839526"></a><pre class="programlisting">#define G_GNUC_FORMAT( arg_idx )</pre><p>Expands to the GNU C <code class="literal">format_arg</code> function attribute if the compiler is <span><strong class="command">gcc</strong></span>.This function attribute specifies that a function takes a formatstring for a <code class="function"><code class="function">printf()</code></code>, <code class="function"><code class="function">scanf()</code></code>, <code class="function"><code class="function">strftime()</code></code> or <code class="function"><code class="function">strfmon()</code></code> stylefunction and modifies it, so that the result can be passed to a <code class="function"><code class="function">printf()</code></code>, <code class="function"><code class="function">scanf()</code></code>, <code class="function"><code class="function">strftime()</code></code> or <code class="function"><code class="function">strfmon()</code></code> style function (with the remaining arguments to the format function the same as they would have been for the unmodified string). See the GNU C documentation for details. </p><div class="informalexample"><pre class="programlisting">gchar *g_dgettext (gchar *domain_name, gchar *msgid) G_GNUC_FORMAT (2);</pre></div><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>arg_idx</code></em> :</span></td><td>the index of the argument.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2839696"></a><h3><a name="G-GNUC-FUNCTION:CAPS"></a>G_GNUC_FUNCTION</h3><a class="indexterm" name="id2839708"></a><pre class="programlisting">#define G_GNUC_FUNCTION</pre><p>Expands to the GNU C <code class="literal">__FUNCTION__</code> variable if the compiler is <span><strong class="command">gcc</strong></span>, or "" if it isn't. The GNU C <code class="literal">__FUNCTION__</code> variable contains the name of the current function. See the GNU C documentation for details. </p></div><hr><div class="refsect2" lang="en"><a name="id2839743"></a><h3><a name="G-GNUC-PRETTY-FUNCTION:CAPS"></a>G_GNUC_PRETTY_FUNCTION</h3><a class="indexterm" name="id2839754"></a><pre class="programlisting">#define G_GNUC_PRETTY_FUNCTION</pre><p>Expands to the GNU C <code class="literal">__PRETTY_FUNCTION__</code> variable if the compiler is <span><strong class="command">gcc</strong></span>, or "" if it isn't.The GNU C <code class="literal">__PRETTY_FUNCTION__</code> variable contains the name of the current function. For a C program this is the same as the <code class="literal">__FUNCTION__</code> variable but for C++ it also includes extra information such as the class and function prototype. See the GNU C documentation for details. </p></div><hr><div class="refsect2" lang="en"><a name="id2839798"></a><h3><a name="G-GNUC-NO-INSTRUMENT:CAPS"></a>G_GNUC_NO_INSTRUMENT</h3><a class="indexterm" name="id2839809"></a><pre class="programlisting">#define G_GNUC_NO_INSTRUMENT</pre><p>Expands to the GNU C <code class="literal">no_instrument_function</code> function attribute if the compiler is <span><strong class="command">gcc</strong></span>. Functions with this attribute will not be instrumented for profiling, when the compiler is called with the<code class="option">-finstrument-functions</code> option.See the GNU C documentation for details. </p></div><hr><div class="refsect2" lang="en"><a name="id2839844"></a><h3><a name="G-HAVE-GNUC-VISIBILITY:CAPS"></a>G_HAVE_GNUC_VISIBILITY</h3><a class="indexterm" name="id2839854"></a><pre class="programlisting">#define G_HAVE_GNUC_VISIBILITY 1</pre><p>This macro is defined as 1 if the the compiler supports ELF visibility attributes (currently only <span><strong class="command">gcc</strong></span>).</p>Since: 2.6</div><hr><div class="refsect2" lang="en"><a name="id2839879"></a><h3><a name="G-GNUC-INTERNAL:CAPS"></a>G_GNUC_INTERNAL</h3><a class="indexterm" name="id2839890"></a><pre class="programlisting">#define G_GNUC_INTERNAL __attribute__((visibility("hidden")))</pre><p>Expands to the GNU C <code class="literal">visibility(hidden)</code> attribute if the compiler supports it (currently only <span><strong class="command">gcc</strong></span>). This attribute can be used for marking library functions as being used internally to the lib only, to not create inefficient PLT entries. Note that static functions do not need to be marked as internal in this way. See the GNU C documentation for details. </p>Since: 2.6</div><hr><div class="refsect2" lang="en"><a name="id2839924"></a><h3><a name="G-LIKELY:CAPS"></a>G_LIKELY()</h3><a class="indexterm" name="id2839935"></a><pre class="programlisting">#define G_LIKELY(expr)</pre><p>Hints the compiler that the expression is likely to evaluate to a truevalue. The compiler may use this information for optimizations.</p><div class="informalexample"><pre class="programlisting">if (G_LIKELY (<code class="function">random()</code> != 1)) g_print ("not one");</pre></div><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>expr</code></em> :</span></td><td>the expression</td></tr></tbody></table></div><p>Since 2.2</p></div><hr><div class="refsect2" lang="en"><a name="id2839994"></a><h3><a name="G-UNLIKELY:CAPS"></a>G_UNLIKELY()</h3><a class="indexterm" name="id2840004"></a><pre class="programlisting">#define G_UNLIKELY(expr)</pre>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -