summaryrefslogtreecommitdiff
path: root/devdocs/gcc~13/common-variable-attributes.html
blob: 3351c861ccc3d77783965a80077a84bb02b3f745 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<div class="subsection-level-extent" id="Common-Variable-Attributes"> <div class="nav-panel"> <p> Next: <a href="arc-variable-attributes" accesskey="n" rel="next">ARC Variable Attributes</a>, Up: <a href="variable-attributes" accesskey="u" rel="up">Specifying Attributes of Variables</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="subsection" id="Common-Variable-Attributes-1"><span>6.34.1 Common Variable Attributes<a class="copiable-link" href="#Common-Variable-Attributes-1"> ¶</a></span></h1> <p>The following attributes are supported on most targets. </p> <dl class="table"> <dt>
<span><code class="code">alias ("<var class="var">target</var>")</code><a class="copiable-link" href="#index-alias-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>The <code class="code">alias</code> variable attribute causes the declaration to be emitted as an alias for another symbol known as an <em class="dfn">alias target</em>. Except for top-level qualifiers the alias target must have the same type as the alias. For instance, the following </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">int var_target;
extern int __attribute__ ((alias ("var_target"))) var_alias;</pre>
</div> <p>defines <code class="code">var_alias</code> to be an alias for the <code class="code">var_target</code> variable. </p> <p>It is an error if the alias target is not defined in the same translation unit as the alias. </p> <p>Note that in the absence of the attribute GCC assumes that distinct declarations with external linkage denote distinct objects. Using both the alias and the alias target to access the same object is undefined in a translation unit without a declaration of the alias with the attribute. </p> <p>This attribute requires assembler and object file support, and may not be available on all targets. </p> </dd> <dt>
<span><code class="code">aligned</code><a class="copiable-link" href="#index-aligned-variable-attribute"> ¶</a></span>
</dt> <dt><code class="code">aligned (<var class="var">alignment</var>)</code></dt> <dd>
<p>The <code class="code">aligned</code> attribute specifies a minimum alignment for the variable or structure field, measured in bytes. When specified, <var class="var">alignment</var> must be an integer constant power of 2. Specifying no <var class="var">alignment</var> argument implies the maximum alignment for the target, which is often, but by no means always, 8 or 16 bytes. </p> <p>For example, the declaration: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">int x __attribute__ ((aligned (16))) = 0;</pre>
</div> <p>causes the compiler to allocate the global variable <code class="code">x</code> on a 16-byte boundary. On a 68040, this could be used in conjunction with an <code class="code">asm</code> expression to access the <code class="code">move16</code> instruction which requires 16-byte aligned operands. </p> <p>You can also specify the alignment of structure fields. For example, to create a double-word aligned <code class="code">int</code> pair, you could write: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">struct foo { int x[2] __attribute__ ((aligned (8))); };</pre>
</div> <p>This is an alternative to creating a union with a <code class="code">double</code> member, which forces the union to be double-word aligned. </p> <p>As in the preceding examples, you can explicitly specify the alignment (in bytes) that you wish the compiler to use for a given variable or structure field. Alternatively, you can leave out the alignment factor and just ask the compiler to align a variable or field to the default alignment for the target architecture you are compiling for. The default alignment is sufficient for all scalar types, but may not be enough for all vector types on a target that supports vector operations. The default alignment is fixed for a particular target ABI. </p> <p>GCC also provides a target specific macro <code class="code">__BIGGEST_ALIGNMENT__</code>, which is the largest alignment ever used for any data type on the target machine you are compiling for. For example, you could write: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">short array[3] __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)));</pre>
</div> <p>The compiler automatically sets the alignment for the declared variable or field to <code class="code">__BIGGEST_ALIGNMENT__</code>. Doing this can often make copy operations more efficient, because the compiler can use whatever instructions copy the biggest chunks of memory when performing copies to or from the variables or fields that you have aligned this way. Note that the value of <code class="code">__BIGGEST_ALIGNMENT__</code> may change depending on command-line options. </p> <p>When used on a struct, or struct member, the <code class="code">aligned</code> attribute can only increase the alignment; in order to decrease it, the <code class="code">packed</code> attribute must be specified as well. When used as part of a typedef, the <code class="code">aligned</code> attribute can both increase and decrease alignment, and specifying the <code class="code">packed</code> attribute generates a warning. </p> <p>Note that the effectiveness of <code class="code">aligned</code> attributes for static variables may be limited by inherent limitations in the system linker and/or object file format. On some systems, the linker is only able to arrange for variables to be aligned up to a certain maximum alignment. (For some linkers, the maximum supported alignment may be very very small.) If your linker is only able to align variables up to a maximum of 8-byte alignment, then specifying <code class="code">aligned(16)</code> in an <code class="code">__attribute__</code> still only provides you with 8-byte alignment. See your linker documentation for further information. </p> <p>Stack variables are not affected by linker restrictions; GCC can properly align them on any target. </p> <p>The <code class="code">aligned</code> attribute can also be used for functions (see <a class="pxref" href="common-function-attributes">Common Function Attributes</a>.) </p> </dd> <dt>
<span><code class="code">warn_if_not_aligned (<var class="var">alignment</var>)</code><a class="copiable-link" href="#index-warn_005fif_005fnot_005faligned-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>This attribute specifies a threshold for the structure field, measured in bytes. If the structure field is aligned below the threshold, a warning will be issued. For example, the declaration: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">struct foo
{
  int i1;
  int i2;
  unsigned long long x __attribute__ ((warn_if_not_aligned (16)));
};</pre>
</div> <p>causes the compiler to issue an warning on <code class="code">struct foo</code>, like ‘<samp class="samp">warning: alignment 8 of 'struct foo' is less than 16</samp>’. The compiler also issues a warning, like ‘<samp class="samp">warning: 'x' offset 8 in 'struct foo' isn't aligned to 16</samp>’, when the structure field has the misaligned offset: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">struct __attribute__ ((aligned (16))) foo
{
  int i1;
  int i2;
  unsigned long long x __attribute__ ((warn_if_not_aligned (16)));
};</pre>
</div> <p>This warning can be disabled by <samp class="option">-Wno-if-not-aligned</samp>. The <code class="code">warn_if_not_aligned</code> attribute can also be used for types (see <a class="pxref" href="common-type-attributes">Common Type Attributes</a>.) </p> </dd> <dt>
<span><code class="code">strict_flex_array (<var class="var">level</var>)</code><a class="copiable-link" href="#index-strict_005fflex_005farray-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>The <code class="code">strict_flex_array</code> attribute should be attached to the trailing array field of a structure. It controls when to treat the trailing array field of a structure as a flexible array member for the purposes of accessing the elements of such an array. <var class="var">level</var> must be an integer betwen 0 to 3. </p> <p><var class="var">level</var>=0 is the least strict level, all trailing arrays of structures are treated as flexible array members. <var class="var">level</var>=3 is the strictest level, only when the trailing array is declared as a flexible array member per C99 standard onwards (‘<samp class="samp">[]</samp>’), it is treated as a flexible array member. </p> <p>There are two more levels in between 0 and 3, which are provided to support older codes that use GCC zero-length array extension (‘<samp class="samp">[0]</samp>’) or one-element array as flexible array members (‘<samp class="samp">[1]</samp>’): When <var class="var">level</var> is 1, the trailing array is treated as a flexible array member when it is declared as either ‘<samp class="samp">[]</samp>’, ‘<samp class="samp">[0]</samp>’, or ‘<samp class="samp">[1]</samp>’; When <var class="var">level</var> is 2, the trailing array is treated as a flexible array member when it is declared as either ‘<samp class="samp">[]</samp>’, or ‘<samp class="samp">[0]</samp>’. </p> <p>This attribute can be used with or without the <samp class="option">-fstrict-flex-arrays</samp>. When both the attribute and the option present at the same time, the level of the strictness for the specific trailing array field is determined by the attribute. </p> </dd> <dt>
<span><code class="code">alloc_size (<var class="var">position</var>)</code><a class="copiable-link" href="#index-alloc_005fsize-variable-attribute"> ¶</a></span>
</dt> <dt><code class="code">alloc_size (<var class="var">position-1</var>, <var class="var">position-2</var>)</code></dt> <dd>
<p>The <code class="code">alloc_size</code> variable attribute may be applied to the declaration of a pointer to a function that returns a pointer and takes at least one argument of an integer type. It indicates that the returned pointer points to an object whose size is given by the function argument at <var class="var">position</var>, or by the product of the arguments at <var class="var">position-1</var> and <var class="var">position-2</var>. Meaningful sizes are positive values less than <code class="code">PTRDIFF_MAX</code>. Other sizes are diagnosed when detected. GCC uses this information to improve the results of <code class="code">__builtin_object_size</code>. </p> <p>For instance, the following declarations </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">typedef __attribute__ ((alloc_size (1, 2))) void*
  (*calloc_ptr) (size_t, size_t);
typedef __attribute__ ((alloc_size (1))) void*
  (*malloc_ptr) (size_t);</pre>
</div> <p>specify that <code class="code">calloc_ptr</code> is a pointer of a function that, like the standard C function <code class="code">calloc</code>, returns an object whose size is given by the product of arguments 1 and 2, and similarly, that <code class="code">malloc_ptr</code>, like the standard C function <code class="code">malloc</code>, returns an object whose size is given by argument 1 to the function. </p> </dd> <dt>
<span><code class="code">cleanup (<var class="var">cleanup_function</var>)</code><a class="copiable-link" href="#index-cleanup-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>The <code class="code">cleanup</code> attribute runs a function when the variable goes out of scope. This attribute can only be applied to auto function scope variables; it may not be applied to parameters or variables with static storage duration. The function must take one parameter, a pointer to a type compatible with the variable. The return value of the function (if any) is ignored. </p> <p>If <samp class="option">-fexceptions</samp> is enabled, then <var class="var">cleanup_function</var> is run during the stack unwinding that happens during the processing of the exception. Note that the <code class="code">cleanup</code> attribute does not allow the exception to be caught, only to perform an action. It is undefined what happens if <var class="var">cleanup_function</var> does not return normally. </p> </dd> <dt>
   <span><code class="code">common</code><a class="copiable-link" href="#index-common-variable-attribute"> ¶</a></span>
</dt> <dt><code class="code">nocommon</code></dt> <dd>
<p>The <code class="code">common</code> attribute requests GCC to place a variable in “common” storage. The <code class="code">nocommon</code> attribute requests the opposite—to allocate space for it directly. </p> <p>These attributes override the default chosen by the <samp class="option">-fno-common</samp> and <samp class="option">-fcommon</samp> flags respectively. </p> </dd> <dt>
<span><code class="code">copy</code><a class="copiable-link" href="#index-copy-variable-attribute"> ¶</a></span>
</dt> <dt><code class="code">copy (<var class="var">variable</var>)</code></dt> <dd>
<p>The <code class="code">copy</code> attribute applies the set of attributes with which <var class="var">variable</var> has been declared to the declaration of the variable to which the attribute is applied. The attribute is designed for libraries that define aliases that are expected to specify the same set of attributes as the aliased symbols. The <code class="code">copy</code> attribute can be used with variables, functions or types. However, the kind of symbol to which the attribute is applied (either varible or function) must match the kind of symbol to which the argument refers. The <code class="code">copy</code> attribute copies only syntactic and semantic attributes but not attributes that affect a symbol’s linkage or visibility such as <code class="code">alias</code>, <code class="code">visibility</code>, or <code class="code">weak</code>. The <code class="code">deprecated</code> attribute is also not copied. See <a class="xref" href="common-function-attributes">Common Function Attributes</a>. See <a class="xref" href="common-type-attributes">Common Type Attributes</a>. </p> </dd> <dt>
<span><code class="code">deprecated</code><a class="copiable-link" href="#index-deprecated-variable-attribute"> ¶</a></span>
</dt> <dt><code class="code">deprecated (<var class="var">msg</var>)</code></dt> <dd>
<p>The <code class="code">deprecated</code> attribute results in a warning if the variable is used anywhere in the source file. This is useful when identifying variables that are expected to be removed in a future version of a program. The warning also includes the location of the declaration of the deprecated variable, to enable users to easily find further information about why the variable is deprecated, or what they should do instead. Note that the warning only occurs for uses: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">extern int old_var __attribute__ ((deprecated));
extern int old_var;
int new_fn () { return old_var; }</pre>
</div> <p>results in a warning on line 3 but not line 2. The optional <var class="var">msg</var> argument, which must be a string, is printed in the warning if present. </p> <p>The <code class="code">deprecated</code> attribute can also be used for functions and types (see <a class="pxref" href="common-function-attributes">Common Function Attributes</a>, see <a class="pxref" href="common-type-attributes">Common Type Attributes</a>). </p> <p>The message attached to the attribute is affected by the setting of the <samp class="option">-fmessage-length</samp> option. </p> </dd> <dt>
<span><code class="code">unavailable</code><a class="copiable-link" href="#index-unavailable-variable-attribute"> ¶</a></span>
</dt> <dt><code class="code">unavailable (<var class="var">msg</var>)</code></dt> <dd>
<p>The <code class="code">unavailable</code> attribute indicates that the variable so marked is not available, if it is used anywhere in the source file. It behaves in the same manner as the <code class="code">deprecated</code> attribute except that the compiler will emit an error rather than a warning. </p> <p>It is expected that items marked as <code class="code">deprecated</code> will eventually be withdrawn from interfaces, and then become unavailable. This attribute allows for marking them appropriately. </p> <p>The <code class="code">unavailable</code> attribute can also be used for functions and types (see <a class="pxref" href="common-function-attributes">Common Function Attributes</a>, see <a class="pxref" href="common-type-attributes">Common Type Attributes</a>). </p> </dd> <dt>
<span><code class="code">mode (<var class="var">mode</var>)</code><a class="copiable-link" href="#index-mode-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>This attribute specifies the data type for the declaration—whichever type corresponds to the mode <var class="var">mode</var>. This in effect lets you request an integer or floating-point type according to its width. </p> <p>See <a data-manual="gccint" href="https://gcc.gnu.org/onlinedocs/gccint/Machine-Modes.html#Machine-Modes">Machine Modes</a> in GNU Compiler Collection (GCC) Internals, for a list of the possible keywords for <var class="var">mode</var>. You may also specify a mode of <code class="code">byte</code> or <code class="code">__byte__</code> to indicate the mode corresponding to a one-byte integer, <code class="code">word</code> or <code class="code">__word__</code> for the mode of a one-word integer, and <code class="code">pointer</code> or <code class="code">__pointer__</code> for the mode used to represent pointers. </p> </dd> <dt>
<span><code class="code">nonstring</code><a class="copiable-link" href="#index-nonstring-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>The <code class="code">nonstring</code> variable attribute specifies that an object or member declaration with type array of <code class="code">char</code>, <code class="code">signed char</code>, or <code class="code">unsigned char</code>, or pointer to such a type is intended to store character arrays that do not necessarily contain a terminating <code class="code">NUL</code>. This is useful in detecting uses of such arrays or pointers with functions that expect <code class="code">NUL</code>-terminated strings, and to avoid warnings when such an array or pointer is used as an argument to a bounded string manipulation function such as <code class="code">strncpy</code>. For example, without the attribute, GCC will issue a warning for the <code class="code">strncpy</code> call below because it may truncate the copy without appending the terminating <code class="code">NUL</code> character. Using the attribute makes it possible to suppress the warning. However, when the array is declared with the attribute the call to <code class="code">strlen</code> is diagnosed because when the array doesn’t contain a <code class="code">NUL</code>-terminated string the call is undefined. To copy, compare, of search non-string character arrays use the <code class="code">memcpy</code>, <code class="code">memcmp</code>, <code class="code">memchr</code>, and other functions that operate on arrays of bytes. In addition, calling <code class="code">strnlen</code> and <code class="code">strndup</code> with such arrays is safe provided a suitable bound is specified, and not diagnosed. </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">struct Data
{
  char name [32] __attribute__ ((nonstring));
};

int f (struct Data *pd, const char *s)
{
  strncpy (pd-&gt;name, s, sizeof pd-&gt;name);
  …
  return strlen (pd-&gt;name);   // unsafe, gets a warning
}</pre>
</div> </dd> <dt>
<span><code class="code">packed</code><a class="copiable-link" href="#index-packed-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>The <code class="code">packed</code> attribute specifies that a structure member should have the smallest possible alignment—one bit for a bit-field and one byte otherwise, unless a larger value is specified with the <code class="code">aligned</code> attribute. The attribute does not apply to non-member objects. </p> <p>For example in the structure below, the member array <code class="code">x</code> is packed so that it immediately follows <code class="code">a</code> with no intervening padding: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">struct foo
{
  char a;
  int x[2] __attribute__ ((packed));
};</pre>
</div> <p><em class="emph">Note:</em> The 4.1, 4.2 and 4.3 series of GCC ignore the <code class="code">packed</code> attribute on bit-fields of type <code class="code">char</code>. This has been fixed in GCC 4.4 but the change can lead to differences in the structure layout. See the documentation of <samp class="option">-Wpacked-bitfield-compat</samp> for more information. </p> </dd> <dt>
<span><code class="code">section ("<var class="var">section-name</var>")</code><a class="copiable-link" href="#index-section-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>Normally, the compiler places the objects it generates in sections like <code class="code">data</code> and <code class="code">bss</code>. Sometimes, however, you need additional sections, or you need certain particular variables to appear in special sections, for example to map to special hardware. The <code class="code">section</code> attribute specifies that a variable (or function) lives in a particular section. For example, this small program uses several specific section names: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">struct duart a __attribute__ ((section ("DUART_A"))) = { 0 };
struct duart b __attribute__ ((section ("DUART_B"))) = { 0 };
char stack[10000] __attribute__ ((section ("STACK"))) = { 0 };
int init_data __attribute__ ((section ("INITDATA")));

main()
{
  /* <span class="r">Initialize stack pointer</span> */
  init_sp (stack + sizeof (stack));

  /* <span class="r">Initialize initialized data</span> */
  memcpy (&amp;init_data, &amp;data, &amp;edata - &amp;data);

  /* <span class="r">Turn on the serial ports</span> */
  init_duart (&amp;a);
  init_duart (&amp;b);
}</pre>
</div> <p>Use the <code class="code">section</code> attribute with <em class="emph">global</em> variables and not <em class="emph">local</em> variables, as shown in the example. </p> <p>You may use the <code class="code">section</code> attribute with initialized or uninitialized global variables but the linker requires each object be defined once, with the exception that uninitialized variables tentatively go in the <code class="code">common</code> (or <code class="code">bss</code>) section and can be multiply “defined”. Using the <code class="code">section</code> attribute changes what section the variable goes into and may cause the linker to issue an error if an uninitialized variable has multiple definitions. You can force a variable to be initialized with the <samp class="option">-fno-common</samp> flag or the <code class="code">nocommon</code> attribute. </p> <p>Some file formats do not support arbitrary sections so the <code class="code">section</code> attribute is not available on all platforms. If you need to map the entire contents of a module to a particular section, consider using the facilities of the linker instead. </p> </dd> <dt>
<span><code class="code">tls_model ("<var class="var">tls_model</var>")</code><a class="copiable-link" href="#index-tls_005fmodel-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>The <code class="code">tls_model</code> attribute sets thread-local storage model (see <a class="pxref" href="thread-local">Thread-Local Storage</a>) of a particular <code class="code">__thread</code> variable, overriding <samp class="option">-ftls-model=</samp> command-line switch on a per-variable basis. The <var class="var">tls_model</var> argument should be one of <code class="code">global-dynamic</code>, <code class="code">local-dynamic</code>, <code class="code">initial-exec</code> or <code class="code">local-exec</code>. </p> <p>Not all targets support this attribute. </p> </dd> <dt>
<span><code class="code">unused</code><a class="copiable-link" href="#index-unused-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>This attribute, attached to a variable or structure field, means that the variable or field is meant to be possibly unused. GCC does not produce a warning for this variable or field. </p> </dd> <dt>
<span><code class="code">used</code><a class="copiable-link" href="#index-used-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>This attribute, attached to a variable with static storage, means that the variable must be emitted even if it appears that the variable is not referenced. </p> <p>When applied to a static data member of a C++ class template, the attribute also means that the member is instantiated if the class itself is instantiated. </p> </dd> <dt>
<span><code class="code">retain</code><a class="copiable-link" href="#index-retain-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>For ELF targets that support the GNU or FreeBSD OSABIs, this attribute will save the variable from linker garbage collection. To support this behavior, variables that have not been placed in specific sections (e.g. by the <code class="code">section</code> attribute, or the <code class="code">-fdata-sections</code> option), will be placed in new, unique sections. </p> <p>This additional functionality requires Binutils version 2.36 or later. </p> </dd> <dt>
<span><code class="code">uninitialized</code><a class="copiable-link" href="#index-uninitialized-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>This attribute, attached to a variable with automatic storage, means that the variable should not be automatically initialized by the compiler when the option <code class="code">-ftrivial-auto-var-init</code> presents. </p> <p>With the option <code class="code">-ftrivial-auto-var-init</code>, all the automatic variables that do not have explicit initializers will be initialized by the compiler. These additional compiler initializations might incur run-time overhead, sometimes dramatically. This attribute can be used to mark some variables to be excluded from such automatical initialization in order to reduce runtime overhead. </p> <p>This attribute has no effect when the option <code class="code">-ftrivial-auto-var-init</code> does not present. </p> </dd> <dt>
<span><code class="code">vector_size (<var class="var">bytes</var>)</code><a class="copiable-link" href="#index-vector_005fsize-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>This attribute specifies the vector size for the type of the declared variable, measured in bytes. The type to which it applies is known as the <em class="dfn">base type</em>. The <var class="var">bytes</var> argument must be a positive power-of-two multiple of the base type size. For example, the declaration: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">int foo __attribute__ ((vector_size (16)));</pre>
</div> <p>causes the compiler to set the mode for <code class="code">foo</code>, to be 16 bytes, divided into <code class="code">int</code> sized units. Assuming a 32-bit <code class="code">int</code>, <code class="code">foo</code>’s type is a vector of four units of four bytes each, and the corresponding mode of <code class="code">foo</code> is <code class="code">V4SI</code>. See <a class="xref" href="vector-extensions">Using Vector Instructions through Built-in Functions</a>, for details of manipulating vector variables. </p> <p>This attribute is only applicable to integral and floating scalars, although arrays, pointers, and function return values are allowed in conjunction with this construct. </p> <p>Aggregates with this attribute are invalid, even if they are of the same size as a corresponding scalar. For example, the declaration: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">struct S { int a; };
struct S  __attribute__ ((vector_size (16))) foo;</pre>
</div> <p>is invalid even if the size of the structure is the same as the size of the <code class="code">int</code>. </p> </dd> <dt>
<span><code class="code">visibility ("<var class="var">visibility_type</var>")</code><a class="copiable-link" href="#index-visibility-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>This attribute affects the linkage of the declaration to which it is attached. The <code class="code">visibility</code> attribute is described in <a class="ref" href="common-function-attributes">Common Function Attributes</a>. </p> </dd> <dt>
<span><code class="code">weak</code><a class="copiable-link" href="#index-weak-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>The <code class="code">weak</code> attribute is described in <a class="ref" href="common-function-attributes">Common Function Attributes</a>. </p> </dd> <dt>
<span><code class="code">noinit</code><a class="copiable-link" href="#index-noinit-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>Any data with the <code class="code">noinit</code> attribute will not be initialized by the C runtime startup code, or the program loader. Not initializing data in this way can reduce program startup times. </p> <p>This attribute is specific to ELF targets and relies on the linker script to place sections with the <code class="code">.noinit</code> prefix in the right location. </p> </dd> <dt>
<span><code class="code">persistent</code><a class="copiable-link" href="#index-persistent-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>Any data with the <code class="code">persistent</code> attribute will not be initialized by the C runtime startup code, but will be initialized by the program loader. This enables the value of the variable to ‘<samp class="samp">persist</samp>’ between processor resets. </p> <p>This attribute is specific to ELF targets and relies on the linker script to place the sections with the <code class="code">.persistent</code> prefix in the right location. Specifically, some type of non-volatile, writeable memory is required. </p> </dd> <dt>
<span><code class="code">objc_nullability (<var class="var">nullability kind</var>) <span class="r">(Objective-C and Objective-C++ only)</span></code><a class="copiable-link" href="#index-objc_005fnullability-variable-attribute"> ¶</a></span>
</dt> <dd>
<p>This attribute applies to pointer variables only. It allows marking the pointer with one of four possible values describing the conditions under which the pointer might have a <code class="code">nil</code> value. In most cases, the attribute is intended to be an internal representation for property and method nullability (specified by language keywords); it is not recommended to use it directly. </p> <p>When <var class="var">nullability kind</var> is <code class="code">"unspecified"</code> or <code class="code">0</code>, nothing is known about the conditions in which the pointer might be <code class="code">nil</code>. Making this state specific serves to avoid false positives in diagnostics. </p> <p>When <var class="var">nullability kind</var> is <code class="code">"nonnull"</code> or <code class="code">1</code>, the pointer has no meaning if it is <code class="code">nil</code> and thus the compiler is free to emit diagnostics if it can be determined that the value will be <code class="code">nil</code>. </p> <p>When <var class="var">nullability kind</var> is <code class="code">"nullable"</code> or <code class="code">2</code>, the pointer might be <code class="code">nil</code> and carry meaning as such. </p> <p>When <var class="var">nullability kind</var> is <code class="code">"resettable"</code> or <code class="code">3</code> (used only in the context of property attribute lists) this describes the case in which a property setter may take the value <code class="code">nil</code> (which perhaps causes the property to be reset in some manner to a default) but for which the property getter will never validly return <code class="code">nil</code>. </p> </dd> </dl> </div>  <div class="nav-panel"> <p> Next: <a href="arc-variable-attributes">ARC Variable Attributes</a>, Up: <a href="variable-attributes">Specifying Attributes of Variables</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">
    &copy; 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/Common-Variable-Attributes.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Common-Variable-Attributes.html</a>
  </p>
</div>