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 2. Boost.Align">
9 <link rel="prev" href="reference.html" title="Reference">
10 <link rel="next" href="compatibility.html" title="Compatibility">
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>
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>
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>
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>
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.
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.
49 <div class="tip"><table border="0" summary="Tip">
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>
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>
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.
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.
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>.
81 <div class="note"><table border="0" summary="Note">
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>
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).
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.
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
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
111 <div class="note"><table border="0" summary="Note">
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>
116 <tr><td align="left" valign="top"><p>
117 This enables the character types to be used as the underlying type for an
122 Comparing alignments is meaningful and provides the obvious results:
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.
128 <li class="listitem">
129 Two alignments are different when their numeric values are not equal.
131 <li class="listitem">
132 When an alignment is larger than another it represents a stricter alignment.
135 <div class="note"><table border="0" summary="Note">
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>
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.
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.
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 © 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>.
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>