您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

548 行
25KB

  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>Common Variable Attributes (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="Common Variable Attributes (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="Common Variable 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="Variable-Attributes.html#Variable-Attributes" rel="up" title="Variable Attributes">
  30. <link href="ARC-Variable-Attributes.html#ARC-Variable-Attributes" rel="next" title="ARC Variable Attributes">
  31. <link href="Variable-Attributes.html#Variable-Attributes" rel="prev" title="Variable Attributes">
  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="Common-Variable-Attributes"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="ARC-Variable-Attributes.html#ARC-Variable-Attributes" accesskey="n" rel="next">ARC Variable Attributes</a>, Up: <a href="Variable-Attributes.html#Variable-Attributes" accesskey="u" rel="up">Variable Attributes</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="Common-Variable-Attributes-1"></a>
  68. <h4 class="subsection">6.34.1 Common Variable Attributes</h4>
  69. <p>The following attributes are supported on most targets.
  70. </p>
  71. <dl compact="compact">
  72. <dt><code>alias (&quot;<var>target</var>&quot;)</code></dt>
  73. <dd><a name="index-alias-variable-attribute"></a>
  74. <p>The <code>alias</code> variable attribute causes the declaration to be emitted
  75. as an alias for another symbol known as an <em>alias target</em>. Except
  76. for top-level qualifiers the alias target must have the same type as
  77. the alias. For instance, the following
  78. </p>
  79. <div class="smallexample">
  80. <pre class="smallexample">int var_target;
  81. extern int __attribute__ ((alias (&quot;var_target&quot;))) var_alias;
  82. </pre></div>
  83. <p>defines <code>var_alias</code> to be an alias for the <code>var_target</code> variable.
  84. </p>
  85. <p>It is an error if the alias target is not defined in the same translation
  86. unit as the alias.
  87. </p>
  88. <p>Note that in the absence of the attribute GCC assumes that distinct
  89. declarations with external linkage denote distinct objects. Using both
  90. the alias and the alias target to access the same object is undefined
  91. in a translation unit without a declaration of the alias with the attribute.
  92. </p>
  93. <p>This attribute requires assembler and object file support, and may not be
  94. available on all targets.
  95. </p>
  96. <a name="index-aligned-variable-attribute"></a>
  97. </dd>
  98. <dt><code>aligned</code></dt>
  99. <dt><code>aligned (<var>alignment</var>)</code></dt>
  100. <dd><p>The <code>aligned</code> attribute specifies a minimum alignment for the variable
  101. or structure field, measured in bytes. When specified, <var>alignment</var> must
  102. be an integer constant power of 2. Specifying no <var>alignment</var> argument
  103. implies the maximum alignment for the target, which is often, but by no
  104. means always, 8 or 16 bytes.
  105. </p>
  106. <p>For example, the declaration:
  107. </p>
  108. <div class="smallexample">
  109. <pre class="smallexample">int x __attribute__ ((aligned (16))) = 0;
  110. </pre></div>
  111. <p>causes the compiler to allocate the global variable <code>x</code> on a
  112. 16-byte boundary. On a 68040, this could be used in conjunction with
  113. an <code>asm</code> expression to access the <code>move16</code> instruction which
  114. requires 16-byte aligned operands.
  115. </p>
  116. <p>You can also specify the alignment of structure fields. For example, to
  117. create a double-word aligned <code>int</code> pair, you could write:
  118. </p>
  119. <div class="smallexample">
  120. <pre class="smallexample">struct foo { int x[2] __attribute__ ((aligned (8))); };
  121. </pre></div>
  122. <p>This is an alternative to creating a union with a <code>double</code> member,
  123. which forces the union to be double-word aligned.
  124. </p>
  125. <p>As in the preceding examples, you can explicitly specify the alignment
  126. (in bytes) that you wish the compiler to use for a given variable or
  127. structure field. Alternatively, you can leave out the alignment factor
  128. and just ask the compiler to align a variable or field to the
  129. default alignment for the target architecture you are compiling for.
  130. The default alignment is sufficient for all scalar types, but may not be
  131. enough for all vector types on a target that supports vector operations.
  132. The default alignment is fixed for a particular target ABI.
  133. </p>
  134. <p>GCC also provides a target specific macro <code>__BIGGEST_ALIGNMENT__</code>,
  135. which is the largest alignment ever used for any data type on the
  136. target machine you are compiling for. For example, you could write:
  137. </p>
  138. <div class="smallexample">
  139. <pre class="smallexample">short array[3] __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)));
  140. </pre></div>
  141. <p>The compiler automatically sets the alignment for the declared
  142. variable or field to <code>__BIGGEST_ALIGNMENT__</code>. Doing this can
  143. often make copy operations more efficient, because the compiler can
  144. use whatever instructions copy the biggest chunks of memory when
  145. performing copies to or from the variables or fields that you have
  146. aligned this way. Note that the value of <code>__BIGGEST_ALIGNMENT__</code>
  147. may change depending on command-line options.
  148. </p>
  149. <p>When used on a struct, or struct member, the <code>aligned</code> attribute can
  150. only increase the alignment; in order to decrease it, the <code>packed</code>
  151. attribute must be specified as well. When used as part of a typedef, the
  152. <code>aligned</code> attribute can both increase and decrease alignment, and
  153. specifying the <code>packed</code> attribute generates a warning.
  154. </p>
  155. <p>Note that the effectiveness of <code>aligned</code> attributes for static
  156. variables may be limited by inherent limitations in the system linker
  157. and/or object file format. On some systems, the linker is
  158. only able to arrange for variables to be aligned up to a certain maximum
  159. alignment. (For some linkers, the maximum supported alignment may
  160. be very very small.) If your linker is only able to align variables
  161. up to a maximum of 8-byte alignment, then specifying <code>aligned(16)</code>
  162. in an <code>__attribute__</code> still only provides you with 8-byte
  163. alignment. See your linker documentation for further information.
  164. </p>
  165. <p>Stack variables are not affected by linker restrictions; GCC can properly
  166. align them on any target.
  167. </p>
  168. <p>The <code>aligned</code> attribute can also be used for functions
  169. (see <a href="Common-Function-Attributes.html#Common-Function-Attributes">Common Function Attributes</a>.)
  170. </p>
  171. <a name="index-warn_005fif_005fnot_005faligned-variable-attribute"></a>
  172. </dd>
  173. <dt><code>warn_if_not_aligned (<var>alignment</var>)</code></dt>
  174. <dd><p>This attribute specifies a threshold for the structure field, measured
  175. in bytes. If the structure field is aligned below the threshold, a
  176. warning will be issued. For example, the declaration:
  177. </p>
  178. <div class="smallexample">
  179. <pre class="smallexample">struct foo
  180. {
  181. int i1;
  182. int i2;
  183. unsigned long long x __attribute__ ((warn_if_not_aligned (16)));
  184. };
  185. </pre></div>
  186. <p>causes the compiler to issue an warning on <code>struct foo</code>, like
  187. &lsquo;<samp>warning: alignment 8 of 'struct foo' is less than 16</samp>&rsquo;.
  188. The compiler also issues a warning, like &lsquo;<samp>warning: 'x' offset
  189. 8 in 'struct foo' isn't aligned to 16</samp>&rsquo;, when the structure field has
  190. the misaligned offset:
  191. </p>
  192. <div class="smallexample">
  193. <pre class="smallexample">struct __attribute__ ((aligned (16))) foo
  194. {
  195. int i1;
  196. int i2;
  197. unsigned long long x __attribute__ ((warn_if_not_aligned (16)));
  198. };
  199. </pre></div>
  200. <p>This warning can be disabled by <samp>-Wno-if-not-aligned</samp>.
  201. The <code>warn_if_not_aligned</code> attribute can also be used for types
  202. (see <a href="Common-Type-Attributes.html#Common-Type-Attributes">Common Type Attributes</a>.)
  203. </p>
  204. </dd>
  205. <dt><code>alloc_size (<var>position</var>)</code></dt>
  206. <dt><code>alloc_size (<var>position-1</var>, <var>position-2</var>)</code></dt>
  207. <dd><a name="index-alloc_005fsize-variable-attribute"></a>
  208. <p>The <code>alloc_size</code> variable attribute may be applied to the declaration
  209. of a pointer to a function that returns a pointer and takes at least one
  210. argument of an integer type. It indicates that the returned pointer points
  211. to an object whose size is given by the function argument at <var>position-1</var>,
  212. or by the product of the arguments at <var>position-1</var> and <var>position-2</var>.
  213. Meaningful sizes are positive values less than <code>PTRDIFF_MAX</code>. Other
  214. sizes are disagnosed when detected. GCC uses this information to improve
  215. the results of <code>__builtin_object_size</code>.
  216. </p>
  217. <p>For instance, the following declarations
  218. </p>
  219. <div class="smallexample">
  220. <pre class="smallexample">typedef __attribute__ ((alloc_size (1, 2))) void*
  221. (*calloc_ptr) (size_t, size_t);
  222. typedef __attribute__ ((alloc_size (1))) void*
  223. (*malloc_ptr) (size_t);
  224. </pre></div>
  225. <p>specify that <code>calloc_ptr</code> is a pointer of a function that, like
  226. the standard C function <code>calloc</code>, returns an object whose size
  227. is given by the product of arguments 1 and 2, and similarly, that
  228. <code>malloc_ptr</code>, like the standard C function <code>malloc</code>,
  229. returns an object whose size is given by argument 1 to the function.
  230. </p>
  231. </dd>
  232. <dt><code>cleanup (<var>cleanup_function</var>)</code></dt>
  233. <dd><a name="index-cleanup-variable-attribute"></a>
  234. <p>The <code>cleanup</code> attribute runs a function when the variable goes
  235. out of scope. This attribute can only be applied to auto function
  236. scope variables; it may not be applied to parameters or variables
  237. with static storage duration. The function must take one parameter,
  238. a pointer to a type compatible with the variable. The return value
  239. of the function (if any) is ignored.
  240. </p>
  241. <p>If <samp>-fexceptions</samp> is enabled, then <var>cleanup_function</var>
  242. is run during the stack unwinding that happens during the
  243. processing of the exception. Note that the <code>cleanup</code> attribute
  244. does not allow the exception to be caught, only to perform an action.
  245. It is undefined what happens if <var>cleanup_function</var> does not
  246. return normally.
  247. </p>
  248. </dd>
  249. <dt><code>common</code></dt>
  250. <dt><code>nocommon</code></dt>
  251. <dd><a name="index-common-variable-attribute"></a>
  252. <a name="index-nocommon-variable-attribute"></a>
  253. <a name="index-fcommon-1"></a>
  254. <a name="index-fno_002dcommon-1"></a>
  255. <p>The <code>common</code> attribute requests GCC to place a variable in
  256. &ldquo;common&rdquo; storage. The <code>nocommon</code> attribute requests the
  257. opposite&mdash;to allocate space for it directly.
  258. </p>
  259. <p>These attributes override the default chosen by the
  260. <samp>-fno-common</samp> and <samp>-fcommon</samp> flags respectively.
  261. </p>
  262. </dd>
  263. <dt><code>copy</code></dt>
  264. <dt><code>copy (<var>variable</var>)</code></dt>
  265. <dd><a name="index-copy-variable-attribute"></a>
  266. <p>The <code>copy</code> attribute applies the set of attributes with which
  267. <var>variable</var> has been declared to the declaration of the variable
  268. to which the attribute is applied. The attribute is designed for
  269. libraries that define aliases that are expected to specify the same
  270. set of attributes as the aliased symbols. The <code>copy</code> attribute
  271. can be used with variables, functions or types. However, the kind
  272. of symbol to which the attribute is applied (either varible or
  273. function) must match the kind of symbol to which the argument refers.
  274. The <code>copy</code> attribute copies only syntactic and semantic attributes
  275. but not attributes that affect a symbol&rsquo;s linkage or visibility such as
  276. <code>alias</code>, <code>visibility</code>, or <code>weak</code>. The <code>deprecated</code>
  277. attribute is also not copied. See <a href="Common-Function-Attributes.html#Common-Function-Attributes">Common Function Attributes</a>.
  278. See <a href="Common-Type-Attributes.html#Common-Type-Attributes">Common Type Attributes</a>.
  279. </p>
  280. </dd>
  281. <dt><code>deprecated</code></dt>
  282. <dt><code>deprecated (<var>msg</var>)</code></dt>
  283. <dd><a name="index-deprecated-variable-attribute"></a>
  284. <p>The <code>deprecated</code> attribute results in a warning if the variable
  285. is used anywhere in the source file. This is useful when identifying
  286. variables that are expected to be removed in a future version of a
  287. program. The warning also includes the location of the declaration
  288. of the deprecated variable, to enable users to easily find further
  289. information about why the variable is deprecated, or what they should
  290. do instead. Note that the warning only occurs for uses:
  291. </p>
  292. <div class="smallexample">
  293. <pre class="smallexample">extern int old_var __attribute__ ((deprecated));
  294. extern int old_var;
  295. int new_fn () { return old_var; }
  296. </pre></div>
  297. <p>results in a warning on line 3 but not line 2. The optional <var>msg</var>
  298. argument, which must be a string, is printed in the warning if
  299. present.
  300. </p>
  301. <p>The <code>deprecated</code> attribute can also be used for functions and
  302. types (see <a href="Common-Function-Attributes.html#Common-Function-Attributes">Common Function Attributes</a>,
  303. see <a href="Common-Type-Attributes.html#Common-Type-Attributes">Common Type Attributes</a>).
  304. </p>
  305. <p>The message attached to the attribute is affected by the setting of
  306. the <samp>-fmessage-length</samp> option.
  307. </p>
  308. </dd>
  309. <dt><code>mode (<var>mode</var>)</code></dt>
  310. <dd><a name="index-mode-variable-attribute"></a>
  311. <p>This attribute specifies the data type for the declaration&mdash;whichever
  312. type corresponds to the mode <var>mode</var>. This in effect lets you
  313. request an integer or floating-point type according to its width.
  314. </p>
  315. <p>See <a href="http://gcc.gnu.org/onlinedocs/gccint/Machine-Modes.html#Machine-Modes">Machine Modes</a> in <cite>GNU Compiler Collection (GCC) Internals</cite>,
  316. for a list of the possible keywords for <var>mode</var>.
  317. You may also specify a mode of <code>byte</code> or <code>__byte__</code> to
  318. indicate the mode corresponding to a one-byte integer, <code>word</code> or
  319. <code>__word__</code> for the mode of a one-word integer, and <code>pointer</code>
  320. or <code>__pointer__</code> for the mode used to represent pointers.
  321. </p>
  322. </dd>
  323. <dt><code>nonstring</code></dt>
  324. <dd><a name="index-nonstring-variable-attribute"></a>
  325. <p>The <code>nonstring</code> variable attribute specifies that an object or member
  326. declaration with type array of <code>char</code>, <code>signed char</code>, or
  327. <code>unsigned char</code>, or pointer to such a type is intended to store
  328. character arrays that do not necessarily contain a terminating <code>NUL</code>.
  329. This is useful in detecting uses of such arrays or pointers with functions
  330. that expect <code>NUL</code>-terminated strings, and to avoid warnings when such
  331. an array or pointer is used as an argument to a bounded string manipulation
  332. function such as <code>strncpy</code>. For example, without the attribute, GCC
  333. will issue a warning for the <code>strncpy</code> call below because it may
  334. truncate the copy without appending the terminating <code>NUL</code> character.
  335. Using the attribute makes it possible to suppress the warning. However,
  336. when the array is declared with the attribute the call to <code>strlen</code> is
  337. diagnosed because when the array doesn&rsquo;t contain a <code>NUL</code>-terminated
  338. string the call is undefined. To copy, compare, of search non-string
  339. character arrays use the <code>memcpy</code>, <code>memcmp</code>, <code>memchr</code>,
  340. and other functions that operate on arrays of bytes. In addition,
  341. calling <code>strnlen</code> and <code>strndup</code> with such arrays is safe
  342. provided a suitable bound is specified, and not diagnosed.
  343. </p>
  344. <div class="smallexample">
  345. <pre class="smallexample">struct Data
  346. {
  347. char name [32] __attribute__ ((nonstring));
  348. };
  349. int f (struct Data *pd, const char *s)
  350. {
  351. strncpy (pd-&gt;name, s, sizeof pd-&gt;name);
  352. &hellip;
  353. return strlen (pd-&gt;name); // unsafe, gets a warning
  354. }
  355. </pre></div>
  356. </dd>
  357. <dt><code>packed</code></dt>
  358. <dd><a name="index-packed-variable-attribute"></a>
  359. <p>The <code>packed</code> attribute specifies that a structure member should have
  360. the smallest possible alignment&mdash;one bit for a bit-field and one byte
  361. otherwise, unless a larger value is specified with the <code>aligned</code>
  362. attribute. The attribute does not apply to non-member objects.
  363. </p>
  364. <p>For example in the structure below, the member array <code>x</code> is packed
  365. so that it immediately follows <code>a</code> with no intervening padding:
  366. </p>
  367. <div class="smallexample">
  368. <pre class="smallexample">struct foo
  369. {
  370. char a;
  371. int x[2] __attribute__ ((packed));
  372. };
  373. </pre></div>
  374. <p><em>Note:</em> The 4.1, 4.2 and 4.3 series of GCC ignore the
  375. <code>packed</code> attribute on bit-fields of type <code>char</code>. This has
  376. been fixed in GCC 4.4 but the change can lead to differences in the
  377. structure layout. See the documentation of
  378. <samp>-Wpacked-bitfield-compat</samp> for more information.
  379. </p>
  380. </dd>
  381. <dt><code>section (&quot;<var>section-name</var>&quot;)</code></dt>
  382. <dd><a name="index-section-variable-attribute"></a>
  383. <p>Normally, the compiler places the objects it generates in sections like
  384. <code>data</code> and <code>bss</code>. Sometimes, however, you need additional sections,
  385. or you need certain particular variables to appear in special sections,
  386. for example to map to special hardware. The <code>section</code>
  387. attribute specifies that a variable (or function) lives in a particular
  388. section. For example, this small program uses several specific section names:
  389. </p>
  390. <div class="smallexample">
  391. <pre class="smallexample">struct duart a __attribute__ ((section (&quot;DUART_A&quot;))) = { 0 };
  392. struct duart b __attribute__ ((section (&quot;DUART_B&quot;))) = { 0 };
  393. char stack[10000] __attribute__ ((section (&quot;STACK&quot;))) = { 0 };
  394. int init_data __attribute__ ((section (&quot;INITDATA&quot;)));
  395. main()
  396. {
  397. /* <span class="roman">Initialize stack pointer</span> */
  398. init_sp (stack + sizeof (stack));
  399. /* <span class="roman">Initialize initialized data</span> */
  400. memcpy (&amp;init_data, &amp;data, &amp;edata - &amp;data);
  401. /* <span class="roman">Turn on the serial ports</span> */
  402. init_duart (&amp;a);
  403. init_duart (&amp;b);
  404. }
  405. </pre></div>
  406. <p>Use the <code>section</code> attribute with
  407. <em>global</em> variables and not <em>local</em> variables,
  408. as shown in the example.
  409. </p>
  410. <p>You may use the <code>section</code> attribute with initialized or
  411. uninitialized global variables but the linker requires
  412. each object be defined once, with the exception that uninitialized
  413. variables tentatively go in the <code>common</code> (or <code>bss</code>) section
  414. and can be multiply &ldquo;defined&rdquo;. Using the <code>section</code> attribute
  415. changes what section the variable goes into and may cause the
  416. linker to issue an error if an uninitialized variable has multiple
  417. definitions. You can force a variable to be initialized with the
  418. <samp>-fno-common</samp> flag or the <code>nocommon</code> attribute.
  419. </p>
  420. <p>Some file formats do not support arbitrary sections so the <code>section</code>
  421. attribute is not available on all platforms.
  422. If you need to map the entire contents of a module to a particular
  423. section, consider using the facilities of the linker instead.
  424. </p>
  425. </dd>
  426. <dt><code>tls_model (&quot;<var>tls_model</var>&quot;)</code></dt>
  427. <dd><a name="index-tls_005fmodel-variable-attribute"></a>
  428. <p>The <code>tls_model</code> attribute sets thread-local storage model
  429. (see <a href="Thread_002dLocal.html#Thread_002dLocal">Thread-Local</a>) of a particular <code>__thread</code> variable,
  430. overriding <samp>-ftls-model=</samp> command-line switch on a per-variable
  431. basis.
  432. The <var>tls_model</var> argument should be one of <code>global-dynamic</code>,
  433. <code>local-dynamic</code>, <code>initial-exec</code> or <code>local-exec</code>.
  434. </p>
  435. <p>Not all targets support this attribute.
  436. </p>
  437. </dd>
  438. <dt><code>unused</code></dt>
  439. <dd><a name="index-unused-variable-attribute"></a>
  440. <p>This attribute, attached to a variable, means that the variable is meant
  441. to be possibly unused. GCC does not produce a warning for this
  442. variable.
  443. </p>
  444. </dd>
  445. <dt><code>used</code></dt>
  446. <dd><a name="index-used-variable-attribute"></a>
  447. <p>This attribute, attached to a variable with static storage, means that
  448. the variable must be emitted even if it appears that the variable is not
  449. referenced.
  450. </p>
  451. <p>When applied to a static data member of a C++ class template, the
  452. attribute also means that the member is instantiated if the
  453. class itself is instantiated.
  454. </p>
  455. </dd>
  456. <dt><code>vector_size (<var>bytes</var>)</code></dt>
  457. <dd><a name="index-vector_005fsize-variable-attribute"></a>
  458. <p>This attribute specifies the vector size for the type of the declared
  459. variable, measured in bytes. The type to which it applies is known as
  460. the <em>base type</em>. The <var>bytes</var> argument must be a positive
  461. power-of-two multiple of the base type size. For example, the declaration:
  462. </p>
  463. <div class="smallexample">
  464. <pre class="smallexample">int foo __attribute__ ((vector_size (16)));
  465. </pre></div>
  466. <p>causes the compiler to set the mode for <code>foo</code>, to be 16 bytes,
  467. divided into <code>int</code> sized units. Assuming a 32-bit <code>int</code>,
  468. <code>foo</code>&rsquo;s type is a vector of four units of four bytes each, and
  469. the corresponding mode of <code>foo</code> is <code>V4SI</code>.
  470. See <a href="Vector-Extensions.html#Vector-Extensions">Vector Extensions</a>, for details of manipulating vector variables.
  471. </p>
  472. <p>This attribute is only applicable to integral and floating scalars,
  473. although arrays, pointers, and function return values are allowed in
  474. conjunction with this construct.
  475. </p>
  476. <p>Aggregates with this attribute are invalid, even if they are of the same
  477. size as a corresponding scalar. For example, the declaration:
  478. </p>
  479. <div class="smallexample">
  480. <pre class="smallexample">struct S { int a; };
  481. struct S __attribute__ ((vector_size (16))) foo;
  482. </pre></div>
  483. <p>is invalid even if the size of the structure is the same as the size of
  484. the <code>int</code>.
  485. </p>
  486. </dd>
  487. <dt><code>visibility (&quot;<var>visibility_type</var>&quot;)</code></dt>
  488. <dd><a name="index-visibility-variable-attribute"></a>
  489. <p>This attribute affects the linkage of the declaration to which it is attached.
  490. The <code>visibility</code> attribute is described in
  491. <a href="Common-Function-Attributes.html#Common-Function-Attributes">Common Function Attributes</a>.
  492. </p>
  493. </dd>
  494. <dt><code>weak</code></dt>
  495. <dd><a name="index-weak-variable-attribute"></a>
  496. <p>The <code>weak</code> attribute is described in
  497. <a href="Common-Function-Attributes.html#Common-Function-Attributes">Common Function Attributes</a>.
  498. </p>
  499. </dd>
  500. <dt><code>noinit</code></dt>
  501. <dd><a name="index-noinit-variable-attribute"></a>
  502. <p>Any data with the <code>noinit</code> attribute will not be initialized by
  503. the C runtime startup code, or the program loader. Not initializing
  504. data in this way can reduce program startup times. This attribute is
  505. specific to ELF targets and relies on the linker to place such data in
  506. the right location
  507. </p>
  508. </dd>
  509. </dl>
  510. <hr>
  511. <div class="header">
  512. <p>
  513. Next: <a href="ARC-Variable-Attributes.html#ARC-Variable-Attributes" accesskey="n" rel="next">ARC Variable Attributes</a>, Up: <a href="Variable-Attributes.html#Variable-Attributes" accesskey="u" rel="up">Variable Attributes</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>
  514. </div>
  515. </body>
  516. </html>