summaryrefslogtreecommitdiff
path: root/devdocs/gcc~13/common-type-attributes.html
blob: 271b9b1a825713455ca762d55b37b7f7bb695f76 (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
<div class="subsection-level-extent" id="Common-Type-Attributes"> <div class="nav-panel"> <p> Next: <a href="arc-type-attributes" accesskey="n" rel="next">ARC Type Attributes</a>, Up: <a href="type-attributes" accesskey="u" rel="up">Specifying Attributes of Types</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-Type-Attributes-1"><span>6.35.1 Common Type Attributes<a class="copiable-link" href="#Common-Type-Attributes-1"> ¶</a></span></h1> <p>The following type attributes are supported on most targets. </p> <dl class="table"> <dt>
<span><code class="code">aligned</code><a class="copiable-link" href="#index-aligned-type-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 (in bytes) for variables of the specified type. When specified, <var class="var">alignment</var> must be a 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. For example, the declarations: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">struct __attribute__ ((aligned (8))) S { short f[3]; };
typedef int more_aligned_int __attribute__ ((aligned (8)));</pre>
</div> <p>force the compiler to ensure (as far as it can) that each variable whose type is <code class="code">struct S</code> or <code class="code">more_aligned_int</code> is allocated and aligned <em class="emph">at least</em> on a 8-byte boundary. On a SPARC, having all variables of type <code class="code">struct S</code> aligned to 8-byte boundaries allows the compiler to use the <code class="code">ldd</code> and <code class="code">std</code> (doubleword load and store) instructions when copying one variable of type <code class="code">struct S</code> to another, thus improving run-time efficiency. </p> <p>Note that the alignment of any given <code class="code">struct</code> or <code class="code">union</code> type is required by the ISO C standard to be at least a perfect multiple of the lowest common multiple of the alignments of all of the members of the <code class="code">struct</code> or <code class="code">union</code> in question. This means that you <em class="emph">can</em> effectively adjust the alignment of a <code class="code">struct</code> or <code class="code">union</code> type by attaching an <code class="code">aligned</code> attribute to any one of the members of such a type, but the notation illustrated in the example above is a more obvious, intuitive, and readable way to request the compiler to adjust the alignment of an entire <code class="code">struct</code> or <code class="code">union</code> type. </p> <p>As in the preceding example, you can explicitly specify the alignment (in bytes) that you wish the compiler to use for a given <code class="code">struct</code> or <code class="code">union</code> type. Alternatively, you can leave out the alignment factor and just ask the compiler to align a type to the maximum useful alignment for the target machine you are compiling for. For example, you could write: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">struct __attribute__ ((aligned)) S { short f[3]; };</pre>
</div> <p>Whenever you leave out the alignment factor in an <code class="code">aligned</code> attribute specification, the compiler automatically sets the alignment for the type to the largest alignment that is ever used for any data type on the target machine you are compiling for. 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 that have types that you have aligned this way. </p> <p>In the example above, if the size of each <code class="code">short</code> is 2 bytes, then the size of the entire <code class="code">struct S</code> type is 6 bytes. The smallest power of two that is greater than or equal to that is 8, so the compiler sets the alignment for the entire <code class="code">struct S</code> type to 8 bytes. </p> <p>Note that although you can ask the compiler to select a time-efficient alignment for a given type and then declare only individual stand-alone objects of that type, the compiler’s ability to select a time-efficient alignment is primarily useful only when you plan to create arrays of variables having the relevant (efficiently aligned) type. If you declare or use arrays of variables of an efficiently-aligned type, then it is likely that your program also does pointer arithmetic (or subscripting, which amounts to the same thing) on pointers to the relevant type, and the code that the compiler generates for these pointer arithmetic operations is often more efficient for efficiently-aligned types than for other types. </p> <p>Note that the effectiveness of <code class="code">aligned</code> attributes may be limited by inherent limitations in your linker. On many 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>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> </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-type-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">typedef unsigned long long __u64
   __attribute__((aligned (4), warn_if_not_aligned (8)));

struct foo
{
  int i1;
  int i2;
  __u64 x;
};</pre>
</div> <p>causes the compiler to issue an warning on <code class="code">struct foo</code>, like ‘<samp class="samp">warning: alignment 4 of 'struct foo' is less than 8</samp>’. It is used to define <code class="code">struct foo</code> in such a way that <code class="code">struct foo</code> has the same layout and the structure field <code class="code">x</code> has the same alignment when <code class="code">__u64</code> is aligned at either 4 or 8 bytes. Align <code class="code">struct foo</code> to 8 bytes: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">struct __attribute__ ((aligned (8))) foo
{
  int i1;
  int i2;
  __u64 x;
};</pre>
</div> <p>silences the warning. The compiler also issues a warning, like ‘<samp class="samp">warning: 'x' offset 12 in 'struct foo' isn't aligned to 8</samp>’, when the structure field has the misaligned offset: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">struct __attribute__ ((aligned (8))) foo
{
  int i1;
  int i2;
  int i3;
  __u64 x;
};</pre>
</div> <p>This warning can be disabled by <samp class="option">-Wno-if-not-aligned</samp>. </p> </dd> <dt>
<span><code class="code">alloc_size (<var class="var">position</var>)</code><a class="copiable-link" href="#index-alloc_005fsize-type-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> type attribute may be applied to the definition of a type of 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-1</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 disagnosed 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_type (size_t, size_t);
typedef __attribute__ ((alloc_size (1))) void*
  malloc_type (size_t);</pre>
</div> <p>specify that <code class="code">calloc_type</code> is a type 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 that <code class="code">malloc_type</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">copy</code><a class="copiable-link" href="#index-copy-type-attribute"> ¶</a></span>
</dt> <dt><code class="code">copy (<var class="var">expression</var>)</code></dt> <dd>
<p>The <code class="code">copy</code> attribute applies the set of attributes with which the type of the <var class="var">expression</var> has been declared to the declaration of the type 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 types, variables, or functions. 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-variable-attributes">Common Variable Attributes</a>. </p> <p>For example, suppose <code class="code">struct A</code> below is defined in some third party library header to have the alignment requirement <code class="code">N</code> and to force a warning whenever a variable of the type is not so aligned due to attribute <code class="code">packed</code>. Specifying the <code class="code">copy</code> attribute on the definition on the unrelated <code class="code">struct B</code> has the effect of copying all relevant attributes from the type referenced by the pointer expression to <code class="code">struct B</code>. </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">struct __attribute__ ((aligned (N), warn_if_not_aligned (N)))
A { /* <span class="r">…</span> */ };
struct __attribute__ ((copy ( (struct A *)0)) B { /* <span class="r">…</span> */ };</pre>
</div> </dd> <dt>
<span><code class="code">deprecated</code><a class="copiable-link" href="#index-deprecated-type-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 type is used anywhere in the source file. This is useful when identifying types that are expected to be removed in a future version of a program. If possible, the warning also includes the location of the declaration of the deprecated type, to enable users to easily find further information about why the type is deprecated, or what they should do instead. Note that the warnings only occur for uses and then only if the type is being applied to an identifier that itself is not being declared as deprecated. </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">typedef int T1 __attribute__ ((deprecated));
T1 x;
typedef T1 T2;
T2 y;
typedef T1 T3 __attribute__ ((deprecated));
T3 z __attribute__ ((deprecated));</pre>
</div> <p>results in a warning on line 2 and 3 but not lines 4, 5, or 6. No warning is issued for line 4 because T2 is not explicitly deprecated. Line 5 has no warning because T3 is explicitly deprecated. Similarly for line 6. The optional <var class="var">msg</var> argument, which must be a string, is printed in the warning if present. Control characters in the string will be replaced with escape sequences, and if the <samp class="option">-fmessage-length</samp> option is set to 0 (its default value) then any newline characters will be ignored. </p> <p>The <code class="code">deprecated</code> attribute can also be used for functions and variables (see <a class="pxref" href="function-attributes">Declaring Attributes of Functions</a>, see <a class="pxref" href="variable-attributes">Specifying Attributes of Variables</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-type-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 behaves in the same manner as the <code class="code">deprecated</code> one, but emits an error rather than a warning. It is used to indicate that a (perhaps previously <code class="code">deprecated</code>) type is no longer usable. </p> <p>The <code class="code">unavailable</code> attribute can also be used for functions and variables (see <a class="pxref" href="function-attributes">Declaring Attributes of Functions</a>, see <a class="pxref" href="variable-attributes">Specifying Attributes of Variables</a>.) </p> </dd> <dt>
<span><code class="code">designated_init</code><a class="copiable-link" href="#index-designated_005finit-type-attribute"> ¶</a></span>
</dt> <dd>
<p>This attribute may only be applied to structure types. It indicates that any initialization of an object of this type must use designated initializers rather than positional initializers. The intent of this attribute is to allow the programmer to indicate that a structure’s layout may change, and that therefore relying on positional initialization will result in future breakage. </p> <p>GCC emits warnings based on this attribute by default; use <samp class="option">-Wno-designated-init</samp> to suppress them. </p> </dd> <dt>
<span><code class="code">may_alias</code><a class="copiable-link" href="#index-may_005falias-type-attribute"> ¶</a></span>
</dt> <dd>
<p>Accesses through pointers to types with this attribute are not subject to type-based alias analysis, but are instead assumed to be able to alias any other type of objects. In the context of section 6.5 paragraph 7 of the C99 standard, an lvalue expression dereferencing such a pointer is treated like having a character type. See <samp class="option">-fstrict-aliasing</samp> for more information on aliasing issues. This extension exists to support some vector APIs, in which pointers to one vector type are permitted to alias pointers to a different vector type. </p> <p>Note that an object of a type with this attribute does not have any special semantics. </p> <p>Example of use: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">typedef short __attribute__ ((__may_alias__)) short_a;

int
main (void)
{
  int a = 0x12345678;
  short_a *b = (short_a *) &amp;a;

  b[1] = 0;

  if (a == 0x12345678)
    abort();

  exit(0);
}</pre>
</div> <p>If you replaced <code class="code">short_a</code> with <code class="code">short</code> in the variable declaration, the above program would abort when compiled with <samp class="option">-fstrict-aliasing</samp>, which is on by default at <samp class="option">-O2</samp> or above. </p> </dd> <dt>
<span><code class="code">mode (<var class="var">mode</var>)</code><a class="copiable-link" href="#index-mode-type-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">packed</code><a class="copiable-link" href="#index-packed-type-attribute"> ¶</a></span>
</dt> <dd>
<p>This attribute, attached to a <code class="code">struct</code>, <code class="code">union</code>, or C++ <code class="code">class</code> type definition, specifies that each of its members (other than zero-width bit-fields) is placed to minimize the memory required. This is equivalent to specifying the <code class="code">packed</code> attribute on each of the members. </p>  <p>When attached to an <code class="code">enum</code> definition, the <code class="code">packed</code> attribute indicates that the smallest integral type should be used. Specifying the <samp class="option">-fshort-enums</samp> flag on the command line is equivalent to specifying the <code class="code">packed</code> attribute on all <code class="code">enum</code> definitions. </p> <p>In the following example <code class="code">struct my_packed_struct</code>’s members are packed closely together, but the internal layout of its <code class="code">s</code> member is not packed—to do that, <code class="code">struct my_unpacked_struct</code> needs to be packed too. </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">struct my_unpacked_struct
 {
    char c;
    int i;
 };

struct __attribute__ ((__packed__)) my_packed_struct
  {
     char c;
     int  i;
     struct my_unpacked_struct s;
  };</pre>
</div> <p>You may only specify the <code class="code">packed</code> attribute on the definition of an <code class="code">enum</code>, <code class="code">struct</code>, <code class="code">union</code>, or <code class="code">class</code>, not on a <code class="code">typedef</code> that does not also define the enumerated type, structure, union, or class. </p> </dd> <dt>
<span><code class="code">scalar_storage_order ("<var class="var">endianness</var>")</code><a class="copiable-link" href="#index-scalar_005fstorage_005forder-type-attribute"> ¶</a></span>
</dt> <dd>
<p>When attached to a <code class="code">union</code> or a <code class="code">struct</code>, this attribute sets the storage order, aka endianness, of the scalar fields of the type, as well as the array fields whose component is scalar. The supported endiannesses are <code class="code">big-endian</code> and <code class="code">little-endian</code>. The attribute has no effects on fields which are themselves a <code class="code">union</code>, a <code class="code">struct</code> or an array whose component is a <code class="code">union</code> or a <code class="code">struct</code>, and it is possible for these fields to have a different scalar storage order than the enclosing type. </p> <p>Note that neither pointer nor vector fields are considered scalar fields in this context, so the attribute has no effects on these fields. </p> <p>This attribute is supported only for targets that use a uniform default scalar storage order (fortunately, most of them), i.e. targets that store the scalars either all in big-endian or all in little-endian. </p> <p>Additional restrictions are enforced for types with the reverse scalar storage order with regard to the scalar storage order of the target: </p> <ul class="itemize mark-bullet"> <li>Taking the address of a scalar field of a <code class="code">union</code> or a <code class="code">struct</code> with reverse scalar storage order is not permitted and yields an error. </li>
<li>Taking the address of an array field, whose component is scalar, of a <code class="code">union</code> or a <code class="code">struct</code> with reverse scalar storage order is permitted but yields a warning, unless <samp class="option">-Wno-scalar-storage-order</samp> is specified. </li>
<li>Taking the address of a <code class="code">union</code> or a <code class="code">struct</code> with reverse scalar storage order is permitted. </li>
</ul> <p>These restrictions exist because the storage order attribute is lost when the address of a scalar or the address of an array with scalar component is taken, so storing indirectly through this address generally does not work. The second case is nevertheless allowed to be able to perform a block copy from or to the array. </p> <p>Moreover, the use of type punning or aliasing to toggle the storage order is not supported; that is to say, if a given scalar object can be accessed through distinct types that assign a different storage order to it, then the behavior is undefined. </p> </dd> <dt>
<span><code class="code">transparent_union</code><a class="copiable-link" href="#index-transparent_005funion-type-attribute"> ¶</a></span>
</dt> <dd> <p>This attribute, attached to a <code class="code">union</code> type definition, indicates that any function parameter having that union type causes calls to that function to be treated in a special way. </p> <p>First, the argument corresponding to a transparent union type can be of any type in the union; no cast is required. Also, if the union contains a pointer type, the corresponding argument can be a null pointer constant or a void pointer expression; and if the union contains a void pointer type, the corresponding argument can be any pointer expression. If the union member type is a pointer, qualifiers like <code class="code">const</code> on the referenced type must be respected, just as with normal pointer conversions. </p> <p>Second, the argument is passed to the function using the calling conventions of the first member of the transparent union, not the calling conventions of the union itself. All members of the union must have the same machine representation; this is necessary for this argument passing to work properly. </p> <p>Transparent unions are designed for library functions that have multiple interfaces for compatibility reasons. For example, suppose the <code class="code">wait</code> function must accept either a value of type <code class="code">int *</code> to comply with POSIX, or a value of type <code class="code">union wait *</code> to comply with the 4.1BSD interface. If <code class="code">wait</code>’s parameter were <code class="code">void *</code>, <code class="code">wait</code> would accept both kinds of arguments, but it would also accept any other pointer type and this would make argument type checking less useful. Instead, <code class="code">&lt;sys/wait.h&gt;</code> might define the interface as follows: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">typedef union __attribute__ ((__transparent_union__))
  {
    int *__ip;
    union wait *__up;
  } wait_status_ptr_t;

pid_t wait (wait_status_ptr_t);</pre>
</div> <p>This interface allows either <code class="code">int *</code> or <code class="code">union wait *</code> arguments to be passed, using the <code class="code">int *</code> calling convention. The program can call <code class="code">wait</code> with arguments of either type: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">int w1 () { int w; return wait (&amp;w); }
int w2 () { union wait w; return wait (&amp;w); }</pre>
</div> <p>With this interface, <code class="code">wait</code>’s implementation might look like this: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">pid_t wait (wait_status_ptr_t p)
{
  return waitpid (-1, p.__ip, 0);
}</pre>
</div> </dd> <dt>
<span><code class="code">unused</code><a class="copiable-link" href="#index-unused-type-attribute"> ¶</a></span>
</dt> <dd>
<p>When attached to a type (including a <code class="code">union</code> or a <code class="code">struct</code>), this attribute means that variables of that type are meant to appear possibly unused. GCC does not produce a warning for any variables of that type, even if the variable appears to do nothing. This is often the case with lock or thread classes, which are usually defined and then not referenced, but contain constructors and destructors that have nontrivial bookkeeping functions. </p> </dd> <dt>
<span><code class="code">vector_size (<var class="var">bytes</var>)</code><a class="copiable-link" href="#index-vector_005fsize-type-attribute"> ¶</a></span>
</dt> <dd>
<p>This attribute specifies the vector size for the type, 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 following declarations: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">typedef __attribute__ ((vector_size (32))) int int_vec32_t ;
typedef __attribute__ ((vector_size (32))) int* int_vec32_ptr_t;
typedef __attribute__ ((vector_size (32))) int int_vec32_arr3_t[3];</pre>
</div> <p>define <code class="code">int_vec32_t</code> to be a 32-byte vector type composed of <code class="code">int</code> sized units. With <code class="code">int</code> having a size of 4 bytes, the type defines a vector of eight units, four bytes each. The mode of variables of type <code class="code">int_vec32_t</code> is <code class="code">V8SI</code>. <code class="code">int_vec32_ptr_t</code> is then defined to be a pointer to such a vector type, and <code class="code">int_vec32_arr3_t</code> to be an array of three such vectors. See <a class="xref" href="vector-extensions">Using Vector Instructions through Built-in Functions</a>, for details of manipulating objects of vector types. </p> <p>This attribute is only applicable to integral and floating scalar types. In function declarations the attribute applies to the function return type. </p> <p>For example, the following: </p>
<div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">__attribute__ ((vector_size (16))) float get_flt_vec16 (void);</pre>
</div> <p>declares <code class="code">get_flt_vec16</code> to be a function returning a 16-byte vector with the base type <code class="code">float</code>. </p> </dd> <dt>
<span><code class="code">visibility</code><a class="copiable-link" href="#index-visibility-type-attribute"> ¶</a></span>
</dt> <dd>
<p>In C++, attribute visibility (see <a class="pxref" href="function-attributes">Declaring Attributes of Functions</a>) can also be applied to class, struct, union and enum types. Unlike other type attributes, the attribute must appear between the initial keyword and the name of the type; it cannot appear after the body of the type. </p> <p>Note that the type visibility is applied to vague linkage entities associated with the class (vtable, typeinfo node, etc.). In particular, if a class is thrown as an exception in one shared object and caught in another, the class must have default visibility. Otherwise the two shared objects are unable to use the same typeinfo node and exception handling will break. </p> </dd> <dt>
<span><code class="code">objc_root_class <span class="r">(Objective-C and Objective-C++ only)</span></code><a class="copiable-link" href="#index-objc_005froot_005fclass-type-attribute"> ¶</a></span>
</dt> <dd>
<p>This attribute marks a class as being a root class, and thus allows the compiler to elide any warnings about a missing superclass and to make additional checks for mandatory methods as needed. </p> </dd> </dl> <p>To specify multiple attributes, separate them by commas within the double parentheses: for example, ‘<samp class="samp">__attribute__ ((aligned (16), packed))</samp>’. </p> </div>  <div class="nav-panel"> <p> Next: <a href="arc-type-attributes">ARC Type Attributes</a>, Up: <a href="type-attributes">Specifying Attributes of Types</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-Type-Attributes.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Common-Type-Attributes.html</a>
  </p>
</div>