Imported Upstream version 1.57.0
[platform/upstream/boost.git] / doc / html / align / vocabulary.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Vocabulary</title>
5 <link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
7 <link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
8 <link rel="up" href="../align.html" title="Chapter&#160;2.&#160;Boost.Align">
9 <link rel="prev" href="reference.html" title="Reference">
10 <link rel="next" href="compatibility.html" title="Compatibility">
11 </head>
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
15 <td align="center"><a href="../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../more/index.htm">More</a></td>
20 </tr></table>
21 <hr>
22 <div class="spirit-nav">
23 <a accesskey="p" href="reference.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../align.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="compatibility.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="section">
26 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
27 <a name="align.vocabulary"></a><a class="link" href="vocabulary.html" title="Vocabulary">Vocabulary</a>
28 </h2></div></div></div>
29 <h4>
30 <a name="align.vocabulary.h0"></a>
31       <span class="phrase"><a name="align.vocabulary.basic_align"></a></span><a class="link" href="vocabulary.html#align.vocabulary.basic_align">[basic.align]</a>
32     </h4>
33 <p>
34       Object types have <span class="bold"><strong>alignment requirements</strong></span> which
35       place restrictions on the addresses at which an object of that type may be
36       allocated. An <span class="bold"><strong>alignment</strong></span> is an implementation-defined
37       integer value representing the number of bytes between successive addresses
38       at which a given object can be allocated. An object type imposes an alignment
39       requirement on every object of that type; stricter alignment can be requested
40       using the alignment specifier.
41     </p>
42 <p>
43       A <span class="bold"><strong>fundamental alignment</strong></span> is represented by
44       an alignment less than or equal to the greatest alignment supported by the
45       implementation in all contexts, which is equal to <code class="computeroutput"><span class="keyword">alignof</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">max_align_t</span><span class="special">)</span></code>.
46       The alignment required for a type might be different when it is used as the
47       type of a complete object and when it is used as the type of a subobject.
48     </p>
49 <div class="tip"><table border="0" summary="Tip">
50 <tr>
51 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../doc/src/images/tip.png"></td>
52 <th align="left">Tip</th>
53 </tr>
54 <tr><td align="left" valign="top">
55 <pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">B</span> <span class="special">{</span> <span class="keyword">long</span> <span class="keyword">double</span> <span class="identifier">d</span><span class="special">;</span> <span class="special">};</span>
56 <span class="keyword">struct</span> <span class="identifier">D</span> <span class="special">:</span> <span class="keyword">virtual</span> <span class="identifier">B</span> <span class="special">{</span> <span class="keyword">char</span> <span class="identifier">c</span><span class="special">;</span> <span class="special">};</span>
57 </pre>
58 <p>
59         When <code class="computeroutput"><span class="identifier">D</span></code> is the type of a complete
60         object, it will have a subobject of type <code class="computeroutput"><span class="identifier">B</span></code>,
61         so it must be aligned appropriately for a <code class="computeroutput"><span class="keyword">long</span>
62         <span class="keyword">double</span></code>. If <code class="computeroutput"><span class="identifier">D</span></code>
63         appears as a subobject of another object that also has <code class="computeroutput"><span class="identifier">B</span></code>
64         as a virtual base class, the <code class="computeroutput"><span class="identifier">B</span></code>
65         subobject might be part of a different subobject, reducing the alignment
66         requirements on the <code class="computeroutput"><span class="identifier">D</span></code> subobject.
67       </p>
68 </td></tr>
69 </table></div>
70 <p>
71       The result of the <code class="computeroutput"><span class="keyword">alignof</span></code> operator
72       reflects the alignment requirement of the type in the complete-object case.
73     </p>
74 <p>
75       An <span class="bold"><strong>extended alignment</strong></span> is represented by an
76       alignment greater than <code class="computeroutput"><span class="keyword">alignof</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">max_align_t</span><span class="special">)</span></code>.
77       It is implementation-defined whether any extended alignments are supported
78       and the contexts in which they are supported. A type having an extended alignment
79       requirement is an <span class="bold"><strong>over-aligned type</strong></span>.
80     </p>
81 <div class="note"><table border="0" summary="Note">
82 <tr>
83 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
84 <th align="left">Note</th>
85 </tr>
86 <tr><td align="left" valign="top"><p>
87         Every over-aligned type is or contains a class type to which extended alignment
88         applies (possibly through a non-static data member).
89       </p></td></tr>
90 </table></div>
91 <p>
92       Alignments are represented as values of the type <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span></code>.
93       Valid alignments include only those values returned by an <code class="computeroutput"><span class="keyword">alignof</span></code>
94       expression for the fundamental types plus an additional implementation-defined
95       set of values, which may be empty. Every alignment value shall be a non-negative
96       integral power of two.
97     </p>
98 <p>
99       Alignments have an order from <span class="bold"><strong>weaker</strong></span> to <span class="bold"><strong>stronger</strong></span> or <span class="bold"><strong>stricter</strong></span>
100       alignments. Stricter alignments have larger alignment values. An address that
101       satisfies an alignment requirement also satisfies any weaker valid alignment
102       requirement.
103     </p>
104 <p>
105       The alignment requirement of a complete type can be queried using an <code class="computeroutput"><span class="keyword">alignof</span></code> expression. Furthermore, the types
106       <code class="computeroutput"><span class="keyword">char</span></code>, <code class="computeroutput"><span class="keyword">signed</span>
107       <span class="keyword">char</span></code>, and <code class="computeroutput"><span class="keyword">unsigned</span>
108       <span class="keyword">char</span></code> shall have the weakest alignment
109       requirement.
110     </p>
111 <div class="note"><table border="0" summary="Note">
112 <tr>
113 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
114 <th align="left">Note</th>
115 </tr>
116 <tr><td align="left" valign="top"><p>
117         This enables the character types to be used as the underlying type for an
118         aligned memory area.
119       </p></td></tr>
120 </table></div>
121 <p>
122       Comparing alignments is meaningful and provides the obvious results:
123     </p>
124 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
125 <li class="listitem">
126           Two alignments are equal when their numeric values are equal.
127         </li>
128 <li class="listitem">
129           Two alignments are different when their numeric values are not equal.
130         </li>
131 <li class="listitem">
132           When an alignment is larger than another it represents a stricter alignment.
133         </li>
134 </ul></div>
135 <div class="note"><table border="0" summary="Note">
136 <tr>
137 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
138 <th align="left">Note</th>
139 </tr>
140 <tr><td align="left" valign="top"><p>
141         The runtime pointer alignment function can be used to obtain an aligned pointer
142         within a buffer; the aligned-storage templates in the library can be used
143         to obtain aligned storage.
144       </p></td></tr>
145 </table></div>
146 <p>
147       If a request for a specific extended alignment in a specific context is not
148       supported by an implementation, the program is ill-formed. Additionally, a
149       request for runtime allocation of dynamic storage for which the requested alignment
150       cannot be honored shall be treated as an allocation failure.
151     </p>
152 </div>
153 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
154 <td align="left"></td>
155 <td align="right"><div class="copyright-footer">Copyright &#169; 2014 Glen Fernandes<p>
156         Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost
157         Software License, Version 1.0</a>.
158       </p>
159 </div></td>
160 </tr></table>
161 <hr>
162 <div class="spirit-nav">
163 <a accesskey="p" href="reference.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../align.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="compatibility.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
164 </div>
165 </body>
166 </html>