Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Function-Attributes.html 15KB

před 3 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Function Attributes (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="Function Attributes (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="Function Attributes (Using the GNU Compiler Collection (GCC))">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="C-Extensions.html#C-Extensions" rel="up" title="C Extensions">
  30. <link href="Common-Function-Attributes.html#Common-Function-Attributes" rel="next" title="Common Function Attributes">
  31. <link href="Mixed-Declarations.html#Mixed-Declarations" rel="prev" title="Mixed Declarations">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Function-Attributes"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Variable-Attributes.html#Variable-Attributes" accesskey="n" rel="next">Variable Attributes</a>, Previous: <a href="Mixed-Declarations.html#Mixed-Declarations" accesskey="p" rel="prev">Mixed Declarations</a>, Up: <a href="C-Extensions.html#C-Extensions" accesskey="u" rel="up">C Extensions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="Declaring-Attributes-of-Functions"></a>
  68. <h3 class="section">6.33 Declaring Attributes of Functions</h3>
  69. <a name="index-function-attributes"></a>
  70. <a name="index-declaring-attributes-of-functions"></a>
  71. <a name="index-volatile-applied-to-function"></a>
  72. <a name="index-const-applied-to-function"></a>
  73. <p>In GNU C and C++, you can use function attributes to specify certain
  74. function properties that may help the compiler optimize calls or
  75. check code more carefully for correctness. For example, you
  76. can use attributes to specify that a function never returns
  77. (<code>noreturn</code>), returns a value depending only on the values of
  78. its arguments (<code>const</code>), or has <code>printf</code>-style arguments
  79. (<code>format</code>).
  80. </p>
  81. <p>You can also use attributes to control memory placement, code
  82. generation options or call/return conventions within the function
  83. being annotated. Many of these attributes are target-specific. For
  84. example, many targets support attributes for defining interrupt
  85. handler functions, which typically must follow special register usage
  86. and return conventions. Such attributes are described in the subsection
  87. for each target. However, a considerable number of attributes are
  88. supported by most, if not all targets. Those are described in
  89. the <a href="Common-Function-Attributes.html#Common-Function-Attributes">Common Function Attributes</a> section.
  90. </p>
  91. <p>Function attributes are introduced by the <code>__attribute__</code> keyword
  92. in the declaration of a function, followed by an attribute specification
  93. enclosed in double parentheses. You can specify multiple attributes in
  94. a declaration by separating them by commas within the double parentheses
  95. or by immediately following one attribute specification with another.
  96. See <a href="Attribute-Syntax.html#Attribute-Syntax">Attribute Syntax</a>, for the exact rules on attribute syntax and
  97. placement. Compatible attribute specifications on distinct declarations
  98. of the same function are merged. An attribute specification that is not
  99. compatible with attributes already applied to a declaration of the same
  100. function is ignored with a warning.
  101. </p>
  102. <p>Some function attributes take one or more arguments that refer to
  103. the function&rsquo;s parameters by their positions within the function parameter
  104. list. Such attribute arguments are referred to as <em>positional arguments</em>.
  105. Unless specified otherwise, positional arguments that specify properties
  106. of parameters with pointer types can also specify the same properties of
  107. the implicit C++ <code>this</code> argument in non-static member functions, and
  108. of parameters of reference to a pointer type. For ordinary functions,
  109. position one refers to the first parameter on the list. In C++ non-static
  110. member functions, position one refers to the implicit <code>this</code> pointer.
  111. The same restrictions and effects apply to function attributes used with
  112. ordinary functions or C++ member functions.
  113. </p>
  114. <p>GCC also supports attributes on
  115. variable declarations (see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>),
  116. labels (see <a href="Label-Attributes.html#Label-Attributes">Label Attributes</a>),
  117. enumerators (see <a href="Enumerator-Attributes.html#Enumerator-Attributes">Enumerator Attributes</a>),
  118. statements (see <a href="Statement-Attributes.html#Statement-Attributes">Statement Attributes</a>),
  119. and types (see <a href="Type-Attributes.html#Type-Attributes">Type Attributes</a>).
  120. </p>
  121. <p>There is some overlap between the purposes of attributes and pragmas
  122. (see <a href="Pragmas.html#Pragmas">Pragmas Accepted by GCC</a>). It has been
  123. found convenient to use <code>__attribute__</code> to achieve a natural
  124. attachment of attributes to their corresponding declarations, whereas
  125. <code>#pragma</code> is of use for compatibility with other compilers
  126. or constructs that do not naturally form part of the grammar.
  127. </p>
  128. <p>In addition to the attributes documented here,
  129. GCC plugins may provide their own attributes.
  130. </p>
  131. <table class="menu" border="0" cellspacing="0">
  132. <tr><td align="left" valign="top">&bull; <a href="Common-Function-Attributes.html#Common-Function-Attributes" accesskey="1">Common Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  133. </td></tr>
  134. <tr><td align="left" valign="top">&bull; <a href="AArch64-Function-Attributes.html#AArch64-Function-Attributes" accesskey="2">AArch64 Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  135. </td></tr>
  136. <tr><td align="left" valign="top">&bull; <a href="AMD-GCN-Function-Attributes.html#AMD-GCN-Function-Attributes" accesskey="3">AMD GCN Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  137. </td></tr>
  138. <tr><td align="left" valign="top">&bull; <a href="ARC-Function-Attributes.html#ARC-Function-Attributes" accesskey="4">ARC Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  139. </td></tr>
  140. <tr><td align="left" valign="top">&bull; <a href="ARM-Function-Attributes.html#ARM-Function-Attributes" accesskey="5">ARM Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  141. </td></tr>
  142. <tr><td align="left" valign="top">&bull; <a href="AVR-Function-Attributes.html#AVR-Function-Attributes" accesskey="6">AVR Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  143. </td></tr>
  144. <tr><td align="left" valign="top">&bull; <a href="Blackfin-Function-Attributes.html#Blackfin-Function-Attributes" accesskey="7">Blackfin Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  145. </td></tr>
  146. <tr><td align="left" valign="top">&bull; <a href="BPF-Function-Attributes.html#BPF-Function-Attributes" accesskey="8">BPF Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  147. </td></tr>
  148. <tr><td align="left" valign="top">&bull; <a href="CR16-Function-Attributes.html#CR16-Function-Attributes" accesskey="9">CR16 Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  149. </td></tr>
  150. <tr><td align="left" valign="top">&bull; <a href="C_002dSKY-Function-Attributes.html#C_002dSKY-Function-Attributes">C-SKY Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  151. </td></tr>
  152. <tr><td align="left" valign="top">&bull; <a href="Epiphany-Function-Attributes.html#Epiphany-Function-Attributes">Epiphany Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  153. </td></tr>
  154. <tr><td align="left" valign="top">&bull; <a href="H8_002f300-Function-Attributes.html#H8_002f300-Function-Attributes">H8/300 Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  155. </td></tr>
  156. <tr><td align="left" valign="top">&bull; <a href="IA_002d64-Function-Attributes.html#IA_002d64-Function-Attributes">IA-64 Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  157. </td></tr>
  158. <tr><td align="left" valign="top">&bull; <a href="M32C-Function-Attributes.html#M32C-Function-Attributes">M32C Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  159. </td></tr>
  160. <tr><td align="left" valign="top">&bull; <a href="M32R_002fD-Function-Attributes.html#M32R_002fD-Function-Attributes">M32R/D Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  161. </td></tr>
  162. <tr><td align="left" valign="top">&bull; <a href="m68k-Function-Attributes.html#m68k-Function-Attributes">m68k Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  163. </td></tr>
  164. <tr><td align="left" valign="top">&bull; <a href="MCORE-Function-Attributes.html#MCORE-Function-Attributes">MCORE Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  165. </td></tr>
  166. <tr><td align="left" valign="top">&bull; <a href="MeP-Function-Attributes.html#MeP-Function-Attributes">MeP Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  167. </td></tr>
  168. <tr><td align="left" valign="top">&bull; <a href="MicroBlaze-Function-Attributes.html#MicroBlaze-Function-Attributes">MicroBlaze Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  169. </td></tr>
  170. <tr><td align="left" valign="top">&bull; <a href="Microsoft-Windows-Function-Attributes.html#Microsoft-Windows-Function-Attributes">Microsoft Windows Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  171. </td></tr>
  172. <tr><td align="left" valign="top">&bull; <a href="MIPS-Function-Attributes.html#MIPS-Function-Attributes">MIPS Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  173. </td></tr>
  174. <tr><td align="left" valign="top">&bull; <a href="MSP430-Function-Attributes.html#MSP430-Function-Attributes">MSP430 Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  175. </td></tr>
  176. <tr><td align="left" valign="top">&bull; <a href="NDS32-Function-Attributes.html#NDS32-Function-Attributes">NDS32 Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  177. </td></tr>
  178. <tr><td align="left" valign="top">&bull; <a href="Nios-II-Function-Attributes.html#Nios-II-Function-Attributes">Nios II Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  179. </td></tr>
  180. <tr><td align="left" valign="top">&bull; <a href="Nvidia-PTX-Function-Attributes.html#Nvidia-PTX-Function-Attributes">Nvidia PTX Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  181. </td></tr>
  182. <tr><td align="left" valign="top">&bull; <a href="PowerPC-Function-Attributes.html#PowerPC-Function-Attributes">PowerPC Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  183. </td></tr>
  184. <tr><td align="left" valign="top">&bull; <a href="RISC_002dV-Function-Attributes.html#RISC_002dV-Function-Attributes">RISC-V Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  185. </td></tr>
  186. <tr><td align="left" valign="top">&bull; <a href="RL78-Function-Attributes.html#RL78-Function-Attributes">RL78 Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  187. </td></tr>
  188. <tr><td align="left" valign="top">&bull; <a href="RX-Function-Attributes.html#RX-Function-Attributes">RX Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  189. </td></tr>
  190. <tr><td align="left" valign="top">&bull; <a href="S_002f390-Function-Attributes.html#S_002f390-Function-Attributes">S/390 Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  191. </td></tr>
  192. <tr><td align="left" valign="top">&bull; <a href="SH-Function-Attributes.html#SH-Function-Attributes">SH Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  193. </td></tr>
  194. <tr><td align="left" valign="top">&bull; <a href="Symbian-OS-Function-Attributes.html#Symbian-OS-Function-Attributes">Symbian OS Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  195. </td></tr>
  196. <tr><td align="left" valign="top">&bull; <a href="V850-Function-Attributes.html#V850-Function-Attributes">V850 Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  197. </td></tr>
  198. <tr><td align="left" valign="top">&bull; <a href="Visium-Function-Attributes.html#Visium-Function-Attributes">Visium Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  199. </td></tr>
  200. <tr><td align="left" valign="top">&bull; <a href="x86-Function-Attributes.html#x86-Function-Attributes">x86 Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  201. </td></tr>
  202. <tr><td align="left" valign="top">&bull; <a href="Xstormy16-Function-Attributes.html#Xstormy16-Function-Attributes">Xstormy16 Function Attributes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
  203. </td></tr>
  204. </table>
  205. <hr>
  206. <div class="header">
  207. <p>
  208. Next: <a href="Variable-Attributes.html#Variable-Attributes" accesskey="n" rel="next">Variable Attributes</a>, Previous: <a href="Mixed-Declarations.html#Mixed-Declarations" accesskey="p" rel="prev">Mixed Declarations</a>, Up: <a href="C-Extensions.html#C-Extensions" accesskey="u" rel="up">C Extensions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  209. </div>
  210. </body>
  211. </html>