• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/toolchains/hndtools-armeabi-2011.09/share/doc/arm-arm-none-eabi/html/gcc/
1<html lang="en">
2<head>
3<title>Variable Attributes - Using the GNU Compiler Collection (GCC)</title>
4<meta http-equiv="Content-Type" content="text/html">
5<meta name="description" content="Using the GNU Compiler Collection (GCC)">
6<meta name="generator" content="makeinfo 4.13">
7<link title="Top" rel="start" href="index.html#Top">
8<link rel="up" href="C-Extensions.html#C-Extensions" title="C Extensions">
9<link rel="prev" href="Character-Escapes.html#Character-Escapes" title="Character Escapes">
10<link rel="next" href="Type-Attributes.html#Type-Attributes" title="Type Attributes">
11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
12<!--
13Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
141998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
152010 Free Software Foundation, Inc.
16
17Permission is granted to copy, distribute and/or modify this document
18under the terms of the GNU Free Documentation License, Version 1.3 or
19any later version published by the Free Software Foundation; with the
20Invariant Sections being ``Funding Free Software'', the Front-Cover
21Texts being (a) (see below), and with the Back-Cover Texts being (b)
22(see below).  A copy of the license is included in the section entitled
23``GNU Free Documentation License''.
24
25(a) The FSF's Front-Cover Text is:
26
27     A GNU Manual
28
29(b) The FSF's Back-Cover Text is:
30
31     You have freedom to copy and modify this GNU Manual, like GNU
32     software.  Copies published by the Free Software Foundation raise
33     funds for GNU development.-->
34<meta http-equiv="Content-Style-Type" content="text/css">
35<style type="text/css"><!--
36  pre.display { font-family:inherit }
37  pre.format  { font-family:inherit }
38  pre.smalldisplay { font-family:inherit; font-size:smaller }
39  pre.smallformat  { font-family:inherit; font-size:smaller }
40  pre.smallexample { font-size:smaller }
41  pre.smalllisp    { font-size:smaller }
42  span.sc    { font-variant:small-caps }
43  span.roman { font-family:serif; font-weight:normal; } 
44  span.sansserif { font-family:sans-serif; font-weight:normal; } 
45--></style>
46<link rel="stylesheet" type="text/css" href="../cs.css">
47</head>
48<body>
49<div class="node">
50<a name="Variable-Attributes"></a>
51<p>
52Next:&nbsp;<a rel="next" accesskey="n" href="Type-Attributes.html#Type-Attributes">Type Attributes</a>,
53Previous:&nbsp;<a rel="previous" accesskey="p" href="Character-Escapes.html#Character-Escapes">Character Escapes</a>,
54Up:&nbsp;<a rel="up" accesskey="u" href="C-Extensions.html#C-Extensions">C Extensions</a>
55<hr>
56</div>
57
58<h3 class="section">6.36 Specifying Attributes of Variables</h3>
59
60<p><a name="index-attribute-of-variables-2571"></a><a name="index-variable-attributes-2572"></a>
61The keyword <code>__attribute__</code> allows you to specify special
62attributes of variables or structure fields.  This keyword is followed
63by an attribute specification inside double parentheses.  Some
64attributes are currently defined generically for variables. 
65Other attributes are defined for variables on particular target
66systems.  Other attributes are available for functions
67(see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>) and for types (see <a href="Type-Attributes.html#Type-Attributes">Type Attributes</a>). 
68Other front ends might define more attributes
69(see <a href="C_002b_002b-Extensions.html#C_002b_002b-Extensions">Extensions to the C++ Language</a>).
70
71 <p>You may also specify attributes with &lsquo;<samp><span class="samp">__</span></samp>&rsquo; preceding and following
72each keyword.  This allows you to use them in header files without
73being concerned about a possible macro of the same name.  For example,
74you may use <code>__aligned__</code> instead of <code>aligned</code>.
75
76 <p>See <a href="Attribute-Syntax.html#Attribute-Syntax">Attribute Syntax</a>, for details of the exact syntax for using
77attributes.
78
79     
80<a name="index-g_t_0040code_007baligned_007d-attribute-2573"></a>
81<dl><dt><code>aligned (</code><var>alignment</var><code>)</code><dd>This attribute specifies a minimum alignment for the variable or
82structure field, measured in bytes.  For example, the declaration:
83
84     <pre class="smallexample">          int x __attribute__ ((aligned (16))) = 0;
85</pre>
86     <p class="noindent">causes the compiler to allocate the global variable <code>x</code> on a
8716-byte boundary.  On a 68040, this could be used in conjunction with
88an <code>asm</code> expression to access the <code>move16</code> instruction which
89requires 16-byte aligned operands.
90
91     <p>You can also specify the alignment of structure fields.  For example, to
92create a double-word aligned <code>int</code> pair, you could write:
93
94     <pre class="smallexample">          struct foo { int x[2] __attribute__ ((aligned (8))); };
95</pre>
96     <p class="noindent">This is an alternative to creating a union with a <code>double</code> member
97that forces the union to be double-word aligned.
98
99     <p>As in the preceding examples, you can explicitly specify the alignment
100(in bytes) that you wish the compiler to use for a given variable or
101structure field.  Alternatively, you can leave out the alignment factor
102and just ask the compiler to align a variable or field to the
103default alignment for the target architecture you are compiling for. 
104The default alignment is sufficient for all scalar types, but may not be
105enough for all vector types on a target which supports vector operations. 
106The default alignment is fixed for a particular target ABI.
107
108     <p>Gcc also provides a target specific macro <code>__BIGGEST_ALIGNMENT__</code>,
109which is the largest alignment ever used for any data type on the
110target machine you are compiling for.  For example, you could write:
111
112     <pre class="smallexample">          short array[3] __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)));
113</pre>
114     <p>The compiler automatically sets the alignment for the declared
115variable or field to <code>__BIGGEST_ALIGNMENT__</code>.  Doing this can
116often make copy operations more efficient, because the compiler can
117use whatever instructions copy the biggest chunks of memory when
118performing copies to or from the variables or fields that you have
119aligned this way.  Note that the value of <code>__BIGGEST_ALIGNMENT__</code>
120may change depending on command line options.
121
122     <p>When used on a struct, or struct member, the <code>aligned</code> attribute can
123only increase the alignment; in order to decrease it, the <code>packed</code>
124attribute must be specified as well.  When used as part of a typedef, the
125<code>aligned</code> attribute can both increase and decrease alignment, and
126specifying the <code>packed</code> attribute will generate a warning.
127
128     <p>Note that the effectiveness of <code>aligned</code> attributes may be limited
129by inherent limitations in your linker.  On many systems, the linker is
130only able to arrange for variables to be aligned up to a certain maximum
131alignment.  (For some linkers, the maximum supported alignment may
132be very very small.)  If your linker is only able to align variables
133up to a maximum of 8 byte alignment, then specifying <code>aligned(16)</code>
134in an <code>__attribute__</code> will still only provide you with 8 byte
135alignment.  See your linker documentation for further information.
136
137     <p>The <code>aligned</code> attribute can also be used for functions
138(see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>.)
139
140     <br><dt><code>cleanup (</code><var>cleanup_function</var><code>)</code><dd><a name="index-g_t_0040code_007bcleanup_007d-attribute-2574"></a>The <code>cleanup</code> attribute runs a function when the variable goes
141out of scope.  This attribute can only be applied to auto function
142scope variables; it may not be applied to parameters or variables
143with static storage duration.  The function must take one parameter,
144a pointer to a type compatible with the variable.  The return value
145of the function (if any) is ignored.
146
147     <p>If <samp><span class="option">-fexceptions</span></samp> is enabled, then <var>cleanup_function</var>
148will be run during the stack unwinding that happens during the
149processing of the exception.  Note that the <code>cleanup</code> attribute
150does not allow the exception to be caught, only to perform an action. 
151It is undefined what happens if <var>cleanup_function</var> does not
152return normally.
153
154     <br><dt><code>common</code><dt><code>nocommon</code><dd><a name="index-g_t_0040code_007bcommon_007d-attribute-2575"></a><a name="index-g_t_0040code_007bnocommon_007d-attribute-2576"></a><a name="index-fcommon-2577"></a><a name="index-fno_002dcommon-2578"></a>The <code>common</code> attribute requests GCC to place a variable in
155&ldquo;common&rdquo; storage.  The <code>nocommon</code> attribute requests the
156opposite&mdash;to allocate space for it directly.
157
158     <p>These attributes override the default chosen by the
159<samp><span class="option">-fno-common</span></samp> and <samp><span class="option">-fcommon</span></samp> flags respectively.
160
161     <br><dt><code>deprecated</code><dt><code>deprecated (</code><var>msg</var><code>)</code><dd><a name="index-g_t_0040code_007bdeprecated_007d-attribute-2579"></a>The <code>deprecated</code> attribute results in a warning if the variable
162is used anywhere in the source file.  This is useful when identifying
163variables that are expected to be removed in a future version of a
164program.  The warning also includes the location of the declaration
165of the deprecated variable, to enable users to easily find further
166information about why the variable is deprecated, or what they should
167do instead.  Note that the warning only occurs for uses:
168
169     <pre class="smallexample">          extern int old_var __attribute__ ((deprecated));
170          extern int old_var;
171          int new_fn () { return old_var; }
172</pre>
173     <p>results in a warning on line 3 but not line 2.  The optional msg
174argument, which must be a string, will be printed in the warning if
175present.
176
177     <p>The <code>deprecated</code> attribute can also be used for functions and
178types (see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>, see <a href="Type-Attributes.html#Type-Attributes">Type Attributes</a>.)
179
180     <br><dt><code>mode (</code><var>mode</var><code>)</code><dd><a name="index-g_t_0040code_007bmode_007d-attribute-2580"></a>This attribute specifies the data type for the declaration&mdash;whichever
181type corresponds to the mode <var>mode</var>.  This in effect lets you
182request an integer or floating point type according to its width.
183
184     <p>You may also specify a mode of &lsquo;<samp><span class="samp">byte</span></samp>&rsquo; or &lsquo;<samp><span class="samp">__byte__</span></samp>&rsquo; to
185indicate the mode corresponding to a one-byte integer, &lsquo;<samp><span class="samp">word</span></samp>&rsquo; or
186&lsquo;<samp><span class="samp">__word__</span></samp>&rsquo; for the mode of a one-word integer, and &lsquo;<samp><span class="samp">pointer</span></samp>&rsquo;
187or &lsquo;<samp><span class="samp">__pointer__</span></samp>&rsquo; for the mode used to represent pointers.
188
189     <br><dt><code>packed</code><dd><a name="index-g_t_0040code_007bpacked_007d-attribute-2581"></a>The <code>packed</code> attribute specifies that a variable or structure field
190should have the smallest possible alignment&mdash;one byte for a variable,
191and one bit for a field, unless you specify a larger value with the
192<code>aligned</code> attribute.
193
194     <p>Here is a structure in which the field <code>x</code> is packed, so that it
195immediately follows <code>a</code>:
196
197     <pre class="smallexample">          struct foo
198          {
199            char a;
200            int x[2] __attribute__ ((packed));
201          };
202</pre>
203     <p><em>Note:</em> The 4.1, 4.2 and 4.3 series of GCC ignore the
204<code>packed</code> attribute on bit-fields of type <code>char</code>.  This has
205been fixed in GCC 4.4 but the change can lead to differences in the
206structure layout.  See the documentation of
207<samp><span class="option">-Wpacked-bitfield-compat</span></samp> for more information.
208
209     <br><dt><code>section ("</code><var>section-name</var><code>")</code><dd><a name="index-g_t_0040code_007bsection_007d-variable-attribute-2582"></a>Normally, the compiler places the objects it generates in sections like
210<code>data</code> and <code>bss</code>.  Sometimes, however, you need additional sections,
211or you need certain particular variables to appear in special sections,
212for example to map to special hardware.  The <code>section</code>
213attribute specifies that a variable (or function) lives in a particular
214section.  For example, this small program uses several specific section names:
215
216     <pre class="smallexample">          struct duart a __attribute__ ((section ("DUART_A"))) = { 0 };
217          struct duart b __attribute__ ((section ("DUART_B"))) = { 0 };
218          char stack[10000] __attribute__ ((section ("STACK"))) = { 0 };
219          int init_data __attribute__ ((section ("INITDATA")));
220          
221          main()
222          {
223            /* <span class="roman">Initialize stack pointer</span> */
224            init_sp (stack + sizeof (stack));
225          
226            /* <span class="roman">Initialize initialized data</span> */
227            memcpy (&amp;init_data, &amp;data, &amp;edata - &amp;data);
228          
229            /* <span class="roman">Turn on the serial ports</span> */
230            init_duart (&amp;a);
231            init_duart (&amp;b);
232          }
233</pre>
234     <p class="noindent">Use the <code>section</code> attribute with
235<em>global</em> variables and not <em>local</em> variables,
236as shown in the example.
237
238     <p>You may use the <code>section</code> attribute with initialized or
239uninitialized global variables but the linker requires
240each object be defined once, with the exception that uninitialized
241variables tentatively go in the <code>common</code> (or <code>bss</code>) section
242and can be multiply &ldquo;defined&rdquo;.  Using the <code>section</code> attribute
243will change what section the variable goes into and may cause the
244linker to issue an error if an uninitialized variable has multiple
245definitions.  You can force a variable to be initialized with the
246<samp><span class="option">-fno-common</span></samp> flag or the <code>nocommon</code> attribute.
247
248     <p>Some file formats do not support arbitrary sections so the <code>section</code>
249attribute is not available on all platforms. 
250If you need to map the entire contents of a module to a particular
251section, consider using the facilities of the linker instead.
252
253     <br><dt><code>shared</code><dd><a name="index-g_t_0040code_007bshared_007d-variable-attribute-2583"></a>On Microsoft Windows, in addition to putting variable definitions in a named
254section, the section can also be shared among all running copies of an
255executable or DLL.  For example, this small program defines shared data
256by putting it in a named section <code>shared</code> and marking the section
257shareable:
258
259     <pre class="smallexample">          int foo __attribute__((section ("shared"), shared)) = 0;
260          
261          int
262          main()
263          {
264            /* <span class="roman">Read and write foo.  All running
265               copies see the same value.</span>  */
266            return 0;
267          }
268</pre>
269     <p class="noindent">You may only use the <code>shared</code> attribute along with <code>section</code>
270attribute with a fully initialized global definition because of the way
271linkers work.  See <code>section</code> attribute for more information.
272
273     <p>The <code>shared</code> attribute is only available on Microsoft Windows.
274
275     <br><dt><code>tls_model ("</code><var>tls_model</var><code>")</code><dd><a name="index-g_t_0040code_007btls_005fmodel_007d-attribute-2584"></a>The <code>tls_model</code> attribute sets thread-local storage model
276(see <a href="Thread_002dLocal.html#Thread_002dLocal">Thread-Local</a>) of a particular <code>__thread</code> variable,
277overriding <samp><span class="option">-ftls-model=</span></samp> command-line switch on a per-variable
278basis. 
279The <var>tls_model</var> argument should be one of <code>global-dynamic</code>,
280<code>local-dynamic</code>, <code>initial-exec</code> or <code>local-exec</code>.
281
282     <p>Not all targets support this attribute.
283
284     <br><dt><code>unused</code><dd>This attribute, attached to a variable, means that the variable is meant
285to be possibly unused.  GCC will not produce a warning for this
286variable.
287
288     <br><dt><code>used</code><dd>This attribute, attached to a variable, means that the variable must be
289emitted even if it appears that the variable is not referenced.
290
291     <br><dt><code>vector_size (</code><var>bytes</var><code>)</code><dd>This attribute specifies the vector size for the variable, measured in
292bytes.  For example, the declaration:
293
294     <pre class="smallexample">          int foo __attribute__ ((vector_size (16)));
295</pre>
296     <p class="noindent">causes the compiler to set the mode for <code>foo</code>, to be 16 bytes,
297divided into <code>int</code> sized units.  Assuming a 32-bit int (a vector of
2984 units of 4 bytes), the corresponding mode of <code>foo</code> will be V4SI.
299
300     <p>This attribute is only applicable to integral and float scalars,
301although arrays, pointers, and function return values are allowed in
302conjunction with this construct.
303
304     <p>Aggregates with this attribute are invalid, even if they are of the same
305size as a corresponding scalar.  For example, the declaration:
306
307     <pre class="smallexample">          struct S { int a; };
308          struct S  __attribute__ ((vector_size (16))) foo;
309</pre>
310     <p class="noindent">is invalid even if the size of the structure is the same as the size of
311the <code>int</code>.
312
313     <br><dt><code>selectany</code><dd>The <code>selectany</code> attribute causes an initialized global variable to
314have link-once semantics.  When multiple definitions of the variable are
315encountered by the linker, the first is selected and the remainder are
316discarded.  Following usage by the Microsoft compiler, the linker is told
317<em>not</em> to warn about size or content differences of the multiple
318definitions.
319
320     <p>Although the primary usage of this attribute is for POD types, the
321attribute can also be applied to global C++ objects that are initialized
322by a constructor.  In this case, the static initialization and destruction
323code for the object is emitted in each translation defining the object,
324but the calls to the constructor and destructor are protected by a
325link-once guard variable.
326
327     <p>The <code>selectany</code> attribute is only available on Microsoft Windows
328targets.  You can use <code>__declspec (selectany)</code> as a synonym for
329<code>__attribute__ ((selectany))</code> for compatibility with other
330compilers.
331
332     <br><dt><code>weak</code><dd>The <code>weak</code> attribute is described in <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>.
333
334     <br><dt><code>dllimport</code><dd>The <code>dllimport</code> attribute is described in <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>.
335
336     <br><dt><code>dllexport</code><dd>The <code>dllexport</code> attribute is described in <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>.
337
338 </dl>
339
340<h4 class="subsection">6.36.1 Blackfin Variable Attributes</h4>
341
342<p>Three attributes are currently defined for the Blackfin.
343
344     <dl>
345<dt><code>l1_data</code><dt><code>l1_data_A</code><dt><code>l1_data_B</code><dd><a name="index-g_t_0040code_007bl1_005fdata_007d-variable-attribute-2585"></a><a name="index-g_t_0040code_007bl1_005fdata_005fA_007d-variable-attribute-2586"></a><a name="index-g_t_0040code_007bl1_005fdata_005fB_007d-variable-attribute-2587"></a>Use these attributes on the Blackfin to place the variable into L1 Data SRAM. 
346Variables with <code>l1_data</code> attribute will be put into the specific section
347named <code>.l1.data</code>. Those with <code>l1_data_A</code> attribute will be put into
348the specific section named <code>.l1.data.A</code>. Those with <code>l1_data_B</code>
349attribute will be put into the specific section named <code>.l1.data.B</code>.
350
351     <br><dt><code>l2</code><dd><a name="index-g_t_0040code_007bl2_007d-variable-attribute-2588"></a>Use this attribute on the Blackfin to place the variable into L2 SRAM. 
352Variables with <code>l2</code> attribute will be put into the specific section
353named <code>.l2.data</code>. 
354</dl>
355
356<h4 class="subsection">6.36.2 M32R/D Variable Attributes</h4>
357
358<p>One attribute is currently defined for the M32R/D.
359
360     <dl>
361<dt><code>model (</code><var>model-name</var><code>)</code><dd><a name="index-variable-addressability-on-the-M32R_002fD-2589"></a>Use this attribute on the M32R/D to set the addressability of an object. 
362The identifier <var>model-name</var> is one of <code>small</code>, <code>medium</code>,
363or <code>large</code>, representing each of the code models.
364
365     <p>Small model objects live in the lower 16MB of memory (so that their
366addresses can be loaded with the <code>ld24</code> instruction).
367
368     <p>Medium and large model objects may live anywhere in the 32-bit address space
369(the compiler will generate <code>seth/add3</code> instructions to load their
370addresses). 
371</dl>
372
373 <p><a name="MeP-Variable-Attributes"></a>
374
375<h4 class="subsection">6.36.3 MeP Variable Attributes</h4>
376
377<p>The MeP target has a number of addressing modes and busses.  The
378<code>near</code> space spans the standard memory space's first 16 megabytes
379(24 bits).  The <code>far</code> space spans the entire 32-bit memory space. 
380The <code>based</code> space is a 128 byte region in the memory space which
381is addressed relative to the <code>$tp</code> register.  The <code>tiny</code>
382space is a 65536 byte region relative to the <code>$gp</code> register.  In
383addition to these memory regions, the MeP target has a separate 16-bit
384control bus which is specified with <code>cb</code> attributes.
385
386     <dl>
387<dt><code>based</code><dd>Any variable with the <code>based</code> attribute will be assigned to the
388<code>.based</code> section, and will be accessed with relative to the
389<code>$tp</code> register.
390
391     <br><dt><code>tiny</code><dd>Likewise, the <code>tiny</code> attribute assigned variables to the
392<code>.tiny</code> section, relative to the <code>$gp</code> register.
393
394     <br><dt><code>near</code><dd>Variables with the <code>near</code> attribute are assumed to have addresses
395that fit in a 24-bit addressing mode.  This is the default for large
396variables (<code>-mtiny=4</code> is the default) but this attribute can
397override <code>-mtiny=</code> for small variables, or override <code>-ml</code>.
398
399     <br><dt><code>far</code><dd>Variables with the <code>far</code> attribute are addressed using a full
40032-bit address.  Since this covers the entire memory space, this
401allows modules to make no assumptions about where variables might be
402stored.
403
404     <br><dt><code>io</code><dt><code>io (</code><var>addr</var><code>)</code><dd>Variables with the <code>io</code> attribute are used to address
405memory-mapped peripherals.  If an address is specified, the variable
406is assigned that address, else it is not assigned an address (it is
407assumed some other module will assign an address).  Example:
408
409     <pre class="example">          int timer_count __attribute__((io(0x123)));
410</pre>
411     <br><dt><code>cb</code><dt><code>cb (</code><var>addr</var><code>)</code><dd>Variables with the <code>cb</code> attribute are used to access the control
412bus, using special instructions.  <code>addr</code> indicates the control bus
413address.  Example:
414
415     <pre class="example">          int cpu_clock __attribute__((cb(0x123)));
416</pre>
417     </dl>
418
419 <p><a name="i386-Variable-Attributes"></a>
420
421<h4 class="subsection">6.36.4 i386 Variable Attributes</h4>
422
423<p>Two attributes are currently defined for i386 configurations:
424<code>ms_struct</code> and <code>gcc_struct</code>
425
426     <dl>
427<dt><code>ms_struct</code><dt><code>gcc_struct</code><dd><a name="index-g_t_0040code_007bms_005fstruct_007d-attribute-2590"></a><a name="index-g_t_0040code_007bgcc_005fstruct_007d-attribute-2591"></a>
428If <code>packed</code> is used on a structure, or if bit-fields are used
429it may be that the Microsoft ABI packs them differently
430than GCC would normally pack them.  Particularly when moving packed
431data between functions compiled with GCC and the native Microsoft compiler
432(either via function call or as data in a file), it may be necessary to access
433either format.
434
435     <p>Currently <samp><span class="option">-m[no-]ms-bitfields</span></samp> is provided for the Microsoft Windows X86
436compilers to match the native Microsoft compiler.
437
438     <p>The Microsoft structure layout algorithm is fairly simple with the exception
439of the bitfield packing:
440
441     <p>The padding and alignment of members of structures and whether a bit field
442can straddle a storage-unit boundary
443
444          <ol type=1 start=1>
445<li>Structure members are stored sequentially in the order in which they are
446declared: the first member has the lowest memory address and the last member
447the highest.
448
449          <li>Every data object has an alignment-requirement. The alignment-requirement
450for all data except structures, unions, and arrays is either the size of the
451object or the current packing size (specified with either the aligned attribute
452or the pack pragma), whichever is less. For structures,  unions, and arrays,
453the alignment-requirement is the largest alignment-requirement of its members. 
454Every object is allocated an offset so that:
455
456          <p>offset %  alignment-requirement == 0
457
458          <li>Adjacent bit fields are packed into the same 1-, 2-, or 4-byte allocation
459unit if the integral types are the same size and if the next bit field fits
460into the current allocation unit without crossing the boundary imposed by the
461common alignment requirements of the bit fields.
462          </ol>
463
464     <p>Handling of zero-length bitfields:
465
466     <p>MSVC interprets zero-length bitfields in the following ways:
467
468          <ol type=1 start=1>
469<li>If a zero-length bitfield is inserted between two bitfields that would
470normally be coalesced, the bitfields will not be coalesced.
471
472          <p>For example:
473
474          <pre class="smallexample">               struct
475                {
476                  unsigned long bf_1 : 12;
477                  unsigned long : 0;
478                  unsigned long bf_2 : 12;
479                } t1;
480</pre>
481          <p>The size of <code>t1</code> would be 8 bytes with the zero-length bitfield.  If the
482zero-length bitfield were removed, <code>t1</code>'s size would be 4 bytes.
483
484          <li>If a zero-length bitfield is inserted after a bitfield, <code>foo</code>, and the
485alignment of the zero-length bitfield is greater than the member that follows it,
486<code>bar</code>, <code>bar</code> will be aligned as the type of the zero-length bitfield.
487
488          <p>For example:
489
490          <pre class="smallexample">               struct
491                {
492                  char foo : 4;
493                  short : 0;
494                  char bar;
495                } t2;
496               
497               struct
498                {
499                  char foo : 4;
500                  short : 0;
501                  double bar;
502                } t3;
503</pre>
504          <p>For <code>t2</code>, <code>bar</code> will be placed at offset 2, rather than offset 1. 
505Accordingly, the size of <code>t2</code> will be 4.  For <code>t3</code>, the zero-length
506bitfield will not affect the alignment of <code>bar</code> or, as a result, the size
507of the structure.
508
509          <p>Taking this into account, it is important to note the following:
510
511               <ol type=1 start=1>
512<li>If a zero-length bitfield follows a normal bitfield, the type of the
513zero-length bitfield may affect the alignment of the structure as whole. For
514example, <code>t2</code> has a size of 4 bytes, since the zero-length bitfield follows a
515normal bitfield, and is of type short.
516
517               <li>Even if a zero-length bitfield is not followed by a normal bitfield, it may
518still affect the alignment of the structure:
519
520               <pre class="smallexample">                    struct
521                     {
522                       char foo : 6;
523                       long : 0;
524                     } t4;
525</pre>
526               <p>Here, <code>t4</code> will take up 4 bytes.
527               </ol>
528
529          <li>Zero-length bitfields following non-bitfield members are ignored:
530
531          <pre class="smallexample">               struct
532                {
533                  char foo;
534                  long : 0;
535                  char bar;
536                } t5;
537</pre>
538          <p>Here, <code>t5</code> will take up 2 bytes.
539          </ol>
540</dl>
541
542<h4 class="subsection">6.36.5 PowerPC Variable Attributes</h4>
543
544<p>Three attributes currently are defined for PowerPC configurations:
545<code>altivec</code>, <code>ms_struct</code> and <code>gcc_struct</code>.
546
547 <p>For full documentation of the struct attributes please see the
548documentation in <a href="i386-Variable-Attributes.html#i386-Variable-Attributes">i386 Variable Attributes</a>.
549
550 <p>For documentation of <code>altivec</code> attribute please see the
551documentation in <a href="PowerPC-Type-Attributes.html#PowerPC-Type-Attributes">PowerPC Type Attributes</a>.
552
553<h4 class="subsection">6.36.6 SPU Variable Attributes</h4>
554
555<p>The SPU supports the <code>spu_vector</code> attribute for variables.  For
556documentation of this attribute please see the documentation in
557<a href="SPU-Type-Attributes.html#SPU-Type-Attributes">SPU Type Attributes</a>.
558
559<h4 class="subsection">6.36.7 Xstormy16 Variable Attributes</h4>
560
561<p>One attribute is currently defined for xstormy16 configurations:
562<code>below100</code>.
563
564     <dl>
565<dt><code>below100</code><dd><a name="index-g_t_0040code_007bbelow100_007d-attribute-2592"></a>
566If a variable has the <code>below100</code> attribute (<code>BELOW100</code> is
567allowed also), GCC will place the variable in the first 0x100 bytes of
568memory and use special opcodes to access it.  Such variables will be
569placed in either the <code>.bss_below100</code> section or the
570<code>.data_below100</code> section.
571
572 </dl>
573
574<h4 class="subsection">6.36.8 AVR Variable Attributes</h4>
575
576     <dl>
577<dt><code>progmem</code><dd><a name="index-g_t_0040code_007bprogmem_007d-variable-attribute-2593"></a>The <code>progmem</code> attribute is used on the AVR to place data in the Program
578Memory address space. The AVR is a Harvard Architecture processor and data
579normally resides in the Data Memory address space. 
580</dl>
581
582 </body></html>
583
584