1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
<div class="section-level-extent" id="Label-Attributes"> <div class="nav-panel"> <p> Next: <a href="enumerator-attributes" accesskey="n" rel="next">Enumerator Attributes</a>, Previous: <a href="type-attributes" accesskey="p" rel="prev">Specifying Attributes of Types</a>, Up: <a href="c-extensions" accesskey="u" rel="up">Extensions to the C Language Family</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div> <h1 class="section" id="Label-Attributes-1"><span>6.36 Label Attributes<a class="copiable-link" href="#Label-Attributes-1"> ¶</a></span></h1> <p>GCC allows attributes to be set on C labels. See <a class="xref" href="attribute-syntax">Attribute Syntax</a>, for details of the exact syntax for using attributes. Other attributes are available for functions (see <a class="pxref" href="function-attributes">Declaring Attributes of Functions</a>), variables (see <a class="pxref" href="variable-attributes">Specifying Attributes of Variables</a>), enumerators (see <a class="pxref" href="enumerator-attributes">Enumerator Attributes</a>), statements (see <a class="pxref" href="statement-attributes">Statement Attributes</a>), and for types (see <a class="pxref" href="type-attributes">Specifying Attributes of Types</a>). A label attribute followed by a declaration appertains to the label and not the declaration. </p> <p>This example uses the <code class="code">cold</code> label attribute to indicate the <code class="code">ErrorHandling</code> branch is unlikely to be taken and that the <code class="code">ErrorHandling</code> label is unused: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">asm goto ("some asm" : : : : NoError);
/* This branch (the fall-through from the asm) is less commonly used */
ErrorHandling:
__attribute__((cold, unused)); /* Semi-colon is required here */
printf("error\n");
return 0;
NoError:
printf("no error\n");
return 1;</pre>
</div> <dl class="table"> <dt>
<span><code class="code">unused</code><a class="copiable-link" href="#index-unused-label-attribute"> ¶</a></span>
</dt> <dd>
<p>This feature is intended for program-generated code that may contain unused labels, but which is compiled with <samp class="option">-Wall</samp>. It is not normally appropriate to use in it human-written code, though it could be useful in cases where the code that jumps to the label is contained within an <code class="code">#ifdef</code> conditional. </p> </dd> <dt>
<span><code class="code">hot</code><a class="copiable-link" href="#index-hot-label-attribute"> ¶</a></span>
</dt> <dd>
<p>The <code class="code">hot</code> attribute on a label is used to inform the compiler that the path following the label is more likely than paths that are not so annotated. This attribute is used in cases where <code class="code">__builtin_expect</code> cannot be used, for instance with computed goto or <code class="code">asm goto</code>. </p> </dd> <dt>
<span><code class="code">cold</code><a class="copiable-link" href="#index-cold-label-attribute"> ¶</a></span>
</dt> <dd>
<p>The <code class="code">cold</code> attribute on labels is used to inform the compiler that the path following the label is unlikely to be executed. This attribute is used in cases where <code class="code">__builtin_expect</code> cannot be used, for instance with computed goto or <code class="code">asm goto</code>. </p> </dd> </dl> </div> <div class="nav-panel"> <p> Next: <a href="enumerator-attributes">Enumerator Attributes</a>, Previous: <a href="type-attributes">Specifying Attributes of Types</a>, Up: <a href="c-extensions">Extensions to the C Language Family</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div><div class="_attribution">
<p class="_attribution-p">
© Free Software Foundation<br>Licensed under the GNU Free Documentation License, Version 1.3.<br>
<a href="https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Label-Attributes.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Label-Attributes.html</a>
</p>
</div>
|