📄 glib-miscellaneous-macros.html
字号:
<p>Expands to the GNU C <code class="literal">pure</code> function attribute if the compiler is <span class="command"><strong>gcc</strong></span>. Declaring a function as pure enables better optimization of calls to the function. A pure function has no effects except its return value and the return value depends only on the parameters and/or global variables.See the GNU C documentation for details. </p></div><hr><div class="refsect2" lang="en"><a name="id2845802"></a><h3><a name="G-GNUC-MALLOC:CAPS"></a>G_GNUC_MALLOC</h3><a class="indexterm" name="id2845817"></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 class="command"><strong>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 class="since">Since 2.6</p></div><hr><div class="refsect2" lang="en"><a name="id2845858"></a><h3><a name="G-GNUC-DEPRECATED:CAPS"></a>G_GNUC_DEPRECATED</h3><a class="indexterm" name="id2845874"></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 class="command"><strong>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 class="since">Since 2.2</p></div><hr><div class="refsect2" lang="en"><a name="id2845915"></a><h3><a name="G-GNUC-NORETURN:CAPS"></a>G_GNUC_NORETURN</h3><a class="indexterm" name="id2845929"></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 class="command"><strong>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="id2845959"></a><h3><a name="G-GNUC-UNUSED:CAPS"></a>G_GNUC_UNUSED</h3><a class="indexterm" name="id2845972"></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 class="command"><strong>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="id2846002"></a><h3><a name="G-GNUC-PRINTF:CAPS"></a>G_GNUC_PRINTF()</h3><a class="indexterm" name="id2846015"></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 class="command"><strong>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><p><span class="term"><em class="parameter"><code>format_idx</code></em> :</span></p></td><td>the index of the argument corresponding to the format string.(The arguments are numbered from 1).</td></tr><tr><td><p><span class="term"><em class="parameter"><code>arg_idx</code></em> :</span></p></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="id2846106"></a><h3><a name="G-GNUC-SCANF:CAPS"></a>G_GNUC_SCANF()</h3><a class="indexterm" name="id2846118"></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 class="command"><strong>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><p><span class="term"><em class="parameter"><code>format_idx</code></em> :</span></p></td><td>the index of the argument corresponding to the format string.(The arguments are numbered from 1).</td></tr><tr><td><p><span class="term"><em class="parameter"><code>arg_idx</code></em> :</span></p></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="id2846198"></a><h3><a name="G-GNUC-FORMAT:CAPS"></a>G_GNUC_FORMAT()</h3><a class="indexterm" name="id2846211"></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 class="command"><strong>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><p><span class="term"><em class="parameter"><code>arg_idx</code></em> :</span></p></td><td>the index of the argument.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2846382"></a><h3><a name="G-GNUC-NULL-TERMINATED:CAPS"></a>G_GNUC_NULL_TERMINATED</h3><a class="indexterm" name="id2846394"></a><pre class="programlisting">#define G_GNUC_NULL_TERMINATED</pre><p>Expands to the GNU C <code class="literal">sentinel</code> function attribute if the compiler is <span class="command"><strong>gcc</strong></span>, or "" if it isn't. This function attributeonly applies to variadic functions and instructs the compiler to check that the argument list is terminated with an explicit <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.See the GNU C documentation for details. </p>Since: 2.8</div><hr><div class="refsect2" lang="en"><a name="id2846438"></a><h3><a name="G-GNUC-WARN-UNUSED-RESULT:CAPS"></a>G_GNUC_WARN_UNUSED_RESULT</h3><a class="indexterm" name="id2846454"></a><pre class="programlisting">#define G_GNUC_WARN_UNUSED_RESULT</pre><p>Expands to the GNU C <code class="literal">warn_unused_result</code> function attribute if the compiler is <span class="command"><strong>gcc</strong></span>, or "" if it isn't. This function attribute makes the compiler emit a warning if the result of a function callis ignored. See the GNU C documentation for details. </p><p class="since">Since 2.10</p></div><hr><div class="refsect2" lang="en"><a name="id2846493"></a><h3><a name="G-GNUC-FUNCTION:CAPS"></a>G_GNUC_FUNCTION</h3><a class="indexterm" name="id2846509"></a><pre class="programlisting">#define G_GNUC_FUNCTION</pre><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Warning</h3><p><code class="literal">G_GNUC_FUNCTION</code> is deprecated and should not be used in newly-written code. 2.16</p></div><p>Expands to "" on all modern compilers, and to <code class="literal">__FUNCTION__</code>on <span class="command"><strong>gcc</strong></span> version 2.x. Don't use it.</p></div><hr><div class="refsect2" lang="en"><a name="id2846549"></a><h3><a name="G-GNUC-PRETTY-FUNCTION:CAPS"></a>G_GNUC_PRETTY_FUNCTION</h3><a class="indexterm" name="id2846564"></a><pre class="programlisting">#define G_GNUC_PRETTY_FUNCTION</pre><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Warning</h3><p><code class="literal">G_GNUC_PRETTY_FUNCTION</code> is deprecated and should not be used in newly-written code. 2.16</p></div><p>Expands to "" on all modern compilers, and to <code class="literal">__PRETTY_FUNCTION__</code> on <span class="command"><strong>gcc</strong></span> version 2.x. Don't use it.</p></div><hr><div class="refsect2" lang="en"><a name="id2846605"></a><h3><a name="G-GNUC-NO-INSTRUMENT:CAPS"></a>G_GNUC_NO_INSTRUMENT</h3><a class="indexterm" name="id2846618"></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 class="command"><strong>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="id2846653"></a><h3><a name="G-HAVE-GNUC-VISIBILITY:CAPS"></a>G_HAVE_GNUC_VISIBILITY</h3><a class="indexterm" name="id2846666"></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 class="command"><strong>gcc</strong></span>).</p>Since: 2.6</div><hr><div class="refsect2" lang="en"><a name="id2846690"></a><h3><a name="G-GNUC-INTERNAL:CAPS"></a>G_GNUC_INTERNAL</h3><a class="indexterm" name="id2846704"></a><pre class="programlisting">#define G_GNUC_INTERNAL</pre><p>This attribute can be used for marking library functions as being used internally to the library only, which may allow the compiler to handlefunction calls more efficiently. Note that static functions do not need to be marked as internal in this way. See the GNU C documentation for details. </p><p>When using a compiler that supports the GNU C hidden visibility attribute, this macro expands to <code class="literal">__attribute__((visibility("hidden")))</code>.When using the Sun Studio compiler, it expands to <code class="literal">__hidden</code>.</p><p>Note that for portability, the attribute should be placed before thefunction declaration. While GCC allows the macro after the declaration, Sun Studio does not.</p><div class="informalexample"><pre class="programlisting">G_GNUC_INTERNALvoid _g_log_fallback_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer unused_data);</pre></div>Since: 2.6</div><hr><div class="refsect2" lang="en"><a name="id2846761"></a><h3><a name="G-GNUC-MAY-ALIAS:CAPS"></a>G_GNUC_MAY_ALIAS</h3><a class="indexterm" name="id2846774"></a><pre class="programlisting">#define G_GNUC_MAY_ALIAS</pre><p></p></div><hr><div class="refsect2" lang="en"><a name="id2846789"></a><h3><a name="G-LIKELY:CAPS"></a>G_LIKELY ()</h3>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -