1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
---|
2 | <html>
|
---|
3 | <!-- Copyright (C) 2022 Richard Stallman and Free Software Foundation, Inc.
|
---|
4 |
|
---|
5 | (The work of Trevis Rothwell and Nelson Beebe has been assigned or
|
---|
6 | licensed to the FSF.)
|
---|
7 |
|
---|
8 | Permission is granted to copy, distribute and/or modify this document
|
---|
9 | under the terms of the GNU Free Documentation License, Version 1.3 or
|
---|
10 | any later version published by the Free Software Foundation; with the
|
---|
11 | Invariant Sections being "GNU General Public License," with the
|
---|
12 | Front-Cover Texts being "A GNU Manual," and with the Back-Cover
|
---|
13 | Texts as in (a) below. A copy of the license is included in the
|
---|
14 | section entitled "GNU Free Documentation License."
|
---|
15 |
|
---|
16 | (a) The FSF's Back-Cover Text is: "You have the freedom to copy and
|
---|
17 | modify this GNU manual. Buying copies from the FSF supports it in
|
---|
18 | developing GNU and promoting software freedom." -->
|
---|
19 | <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
|
---|
20 | <head>
|
---|
21 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
---|
22 | <title>Attributes (GNU C Language Manual)</title>
|
---|
23 |
|
---|
24 | <meta name="description" content="Attributes (GNU C Language Manual)">
|
---|
25 | <meta name="keywords" content="Attributes (GNU C Language Manual)">
|
---|
26 | <meta name="resource-type" content="document">
|
---|
27 | <meta name="distribution" content="global">
|
---|
28 | <meta name="Generator" content="makeinfo">
|
---|
29 | <link href="index.html" rel="start" title="Top">
|
---|
30 | <link href="Symbol-Index.html" rel="index" title="Symbol Index">
|
---|
31 | <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
---|
32 | <link href="index.html" rel="up" title="Top">
|
---|
33 | <link href="Signals.html" rel="next" title="Signals">
|
---|
34 | <link href="Digraphs.html" rel="prev" title="Digraphs">
|
---|
35 | <style type="text/css">
|
---|
36 | <!--
|
---|
37 | a.summary-letter {text-decoration: none}
|
---|
38 | blockquote.indentedblock {margin-right: 0em}
|
---|
39 | div.display {margin-left: 3.2em}
|
---|
40 | div.example {margin-left: 3.2em}
|
---|
41 | div.lisp {margin-left: 3.2em}
|
---|
42 | kbd {font-style: oblique}
|
---|
43 | pre.display {font-family: inherit}
|
---|
44 | pre.format {font-family: inherit}
|
---|
45 | pre.menu-comment {font-family: serif}
|
---|
46 | pre.menu-preformatted {font-family: serif}
|
---|
47 | span.nolinebreak {white-space: nowrap}
|
---|
48 | span.roman {font-family: initial; font-weight: normal}
|
---|
49 | span.sansserif {font-family: sans-serif; font-weight: normal}
|
---|
50 | ul.no-bullet {list-style: none}
|
---|
51 | -->
|
---|
52 | </style>
|
---|
53 |
|
---|
54 |
|
---|
55 | </head>
|
---|
56 |
|
---|
57 | <body lang="en">
|
---|
58 | <span id="Attributes"></span><div class="header">
|
---|
59 | <p>
|
---|
60 | Next: <a href="Signals.html" accesskey="n" rel="next">Signals</a>, Previous: <a href="Digraphs.html" accesskey="p" rel="prev">Digraphs</a>, Up: <a href="index.html" accesskey="u" rel="up">Top</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
|
---|
61 | </div>
|
---|
62 | <hr>
|
---|
63 | <span id="Attributes-in-Declarations"></span><h2 class="appendix">Appendix D Attributes in Declarations</h2>
|
---|
64 | <span id="index-attributes"></span>
|
---|
65 | <span id="index-_005f_005fattribute_005f_005f"></span>
|
---|
66 |
|
---|
67 | <p>You can specify certain additional requirements in a declaration, to
|
---|
68 | get fine-grained control over code generation, and helpful
|
---|
69 | informational messages during compilation. We use a few attributes in
|
---|
70 | code examples throughout this manual, including
|
---|
71 | </p>
|
---|
72 | <dl compact="compact">
|
---|
73 | <dt><code>aligned</code></dt>
|
---|
74 | <dd><p>The <code>aligned</code> attribute specifies a minimum alignment for a
|
---|
75 | variable or structure field, measured in bytes:
|
---|
76 | </p>
|
---|
77 | <div class="example">
|
---|
78 | <pre class="example">int foo __attribute__ ((aligned (8))) = 0;
|
---|
79 | </pre></div>
|
---|
80 |
|
---|
81 | <p>This directs GNU C to allocate <code>foo</code> at an address that is a
|
---|
82 | multiple of 8 bytes. However, you can’t force an alignment bigger
|
---|
83 | than the computer’s maximum meaningful alignment.
|
---|
84 | </p>
|
---|
85 | </dd>
|
---|
86 | <dt><code>packed</code></dt>
|
---|
87 | <dd><p>The <code>packed</code> attribute specifies to compact the fields of a
|
---|
88 | structure by not leaving gaps between fields. For example,
|
---|
89 | </p>
|
---|
90 | <div class="example">
|
---|
91 | <pre class="example">struct __attribute__ ((packed)) bar
|
---|
92 | {
|
---|
93 | char a;
|
---|
94 | int b;
|
---|
95 | };
|
---|
96 | </pre></div>
|
---|
97 |
|
---|
98 | <p>allocates the integer field <code>b</code> at byte 1 in the structure,
|
---|
99 | immediately after the character field <code>a</code>. The packed structure
|
---|
100 | is just 5 bytes long (assuming <code>int</code> is 4 bytes) and its
|
---|
101 | alignment is 1, that of <code>char</code>.
|
---|
102 | </p>
|
---|
103 | </dd>
|
---|
104 | <dt><code>deprecated</code></dt>
|
---|
105 | <dd><p>Applicable to both variables and functions, the <code>deprecated</code>
|
---|
106 | attribute tells the compiler to issue a warning if the variable or
|
---|
107 | function is ever used in the source file.
|
---|
108 | </p>
|
---|
109 | <div class="example">
|
---|
110 | <pre class="example">int old_foo __attribute__ ((deprecated));
|
---|
111 |
|
---|
112 | int old_quux () __attribute__ ((deprecated));
|
---|
113 | </pre></div>
|
---|
114 |
|
---|
115 | </dd>
|
---|
116 | <dt><code>__noinline__</code></dt>
|
---|
117 | <dd><p>The <code>__noinline__</code> attribute, in a function’s declaration or
|
---|
118 | definition, specifies never to inline calls to that function. All
|
---|
119 | calls to that function, in a compilation unit where it has this
|
---|
120 | attribute, will be compiled to invoke the separately compiled
|
---|
121 | function. See <a href="Inline-Function-Definitions.html">Inline Function Definitions</a>.
|
---|
122 | </p>
|
---|
123 | </dd>
|
---|
124 | <dt><code>__noclone__</code></dt>
|
---|
125 | <dd><p>The <code>__noclone__</code> attribute, in a function’s declaration or
|
---|
126 | definition, specifies never to clone that function. Thus, there will
|
---|
127 | be only one compiled version of the function. See <a href="Label-Value-Caveats.html">Label Value Caveats</a>, for more information about cloning.
|
---|
128 | </p>
|
---|
129 | </dd>
|
---|
130 | <dt><code>always_inline</code></dt>
|
---|
131 | <dd><p>The <code>always_inline</code> attribute, in a function’s declaration or
|
---|
132 | definition, specifies to inline all calls to that function (unless
|
---|
133 | something about the function makes inlining impossible). This applies
|
---|
134 | to all calls to that function in a compilation unit where it has this
|
---|
135 | attribute. See <a href="Inline-Function-Definitions.html">Inline Function Definitions</a>.
|
---|
136 | </p>
|
---|
137 | </dd>
|
---|
138 | <dt><code>gnu_inline</code></dt>
|
---|
139 | <dd><p>The <code>gnu_inline</code> attribute, in a function’s declaration or
|
---|
140 | definition, specifies to handle the <code>inline</code> keywprd the way GNU
|
---|
141 | C originally implemented it, many years before ISO C said anything
|
---|
142 | about inlining. See <a href="Inline-Function-Definitions.html">Inline Function Definitions</a>.
|
---|
143 | </p></dd>
|
---|
144 | </dl>
|
---|
145 |
|
---|
146 | <p>For full documentation of attributes, see the GCC manual.
|
---|
147 | See <a href="https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax">System Headers</a> in <cite>Using
|
---|
148 | the GNU Compiler Collection</cite>.
|
---|
149 | </p>
|
---|
150 | <hr>
|
---|
151 | <div class="header">
|
---|
152 | <p>
|
---|
153 | Next: <a href="Signals.html" accesskey="n" rel="next">Signals</a>, Previous: <a href="Digraphs.html" accesskey="p" rel="prev">Digraphs</a>, Up: <a href="index.html" accesskey="u" rel="up">Top</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
|
---|
154 | </div>
|
---|
155 |
|
---|
156 |
|
---|
157 |
|
---|
158 | </body>
|
---|
159 | </html>
|
---|