6.34 Label Attributes
GCC allows attributes to be set on C labels. See Attribute Syntax, for details of the exact syntax for using attributes. Other attributes are available for functions (see Function Attributes), variables (see Variable Attributes), enumerators (see Enumerator Attributes), and for types (see Type Attributes).
This example uses the cold
label attribute to indicate the ErrorHandling
branch is unlikely to be taken and that the ErrorHandling
label is unused:
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;
unused
-
This feature is intended for program-generated code that may contain unused labels, but which is compiled with -Wall. 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
#ifdef
conditional. hot
-
The
hot
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__builtin_expect
cannot be used, for instance with computed goto orasm goto
. cold
-
The
cold
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__builtin_expect
cannot be used, for instance with computed goto orasm goto
.
Next: Enumerator Attributes, Previous: Type Attributes, Up: C Extensions [Contents][Index]
© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-6.4.0/gcc/Label-Attributes.html