summaryrefslogtreecommitdiff
path: root/doc/html/align/vocabulary.html
blob: e05189a65d36aec3af5427dafb879e2ae4881cfc (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
142
143
144
145
146
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Vocabulary</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../align.html" title="Chapter&#160;3.&#160;Boost.Align">
<link rel="prev" href="reference.html" title="Reference">
<link rel="next" href="compatibility.html" title="Compatibility">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="align.vocabulary"></a><a class="link" href="vocabulary.html" title="Vocabulary">Vocabulary</a>
</h2></div></div></div>
<h4>
<a name="align.vocabulary.h0"></a>
      <span class="phrase"><a name="align.vocabulary.basic_align"></a></span><a class="link" href="vocabulary.html#align.vocabulary.basic_align">[basic.align]</a>
    </h4>
<p>
      Object types have <span class="emphasis"><em>alignment requirements</em></span> which place restrictions
      on the addresses at which an object of that type may be allocated. An <span class="emphasis"><em>alignment</em></span>
      is an implementation-defined integer value representing the number of bytes
      between successive addresses at which a given object can be allocated. An object
      type imposes an alignment requirement on every object of that type; stricter
      alignment can be requested using the alignment specifier.
    </p>
<p>
      A <span class="emphasis"><em>fundamental alignment</em></span> is represented by an alignment
      less than or equal to the greatest alignment supported by the 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>.
      The alignment required for a type might be different when it is used as the
      type of a complete object and when it is used as the type of a subobject. [<span class="emphasis"><em>Example:</em></span>
    </p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
          <code class="computeroutput"><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></code>
        </li>
<li class="listitem">
          <code class="computeroutput"><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></code>
        </li>
</ol></div>
<p>
      When <code class="computeroutput"><span class="identifier">D</span></code> is the type of a complete
      object, it will have a subobject of type <code class="computeroutput"><span class="identifier">B</span></code>,
      so it must be aligned appropriately for a <code class="computeroutput"><span class="keyword">long</span>
      <span class="keyword">double</span></code>. If <code class="computeroutput"><span class="identifier">D</span></code>
      appears as a subobject of another object that also has <code class="computeroutput"><span class="identifier">B</span></code>
      as a virtual base class, the <code class="computeroutput"><span class="identifier">B</span></code>
      subobject might be part of a different subobject, reducing the alignment requirements
      on the <code class="computeroutput"><span class="identifier">D</span></code> subobject. &#8212;<span class="emphasis"><em>end
      example</em></span>] The result of the <code class="computeroutput"><span class="keyword">alignof</span></code>
      operator reflects the alignment requirement of the type in the complete-object
      case.
    </p>
<p>
      An <span class="emphasis"><em>extended alignment</em></span> is represented by an 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>. It is implementation-defined whether any
      extended alignments are supported and the contexts in which they are supported.
      A type having an extended alignment requirement is an <span class="emphasis"><em>over-aligned
      type</em></span>. [<span class="emphasis"><em>Note:</em></span> Every over-aligned type is or
      contains a class type to which extended alignment applies (possibly through
      a non-static data member). &#8212;<span class="emphasis"><em>end note</em></span>]
    </p>
<p>
      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>.
      Valid alignments include only those values returned by an <code class="computeroutput"><span class="keyword">alignof</span></code>
      expression for the fundamental types plus an additional implementation-defined
      set of values, which may be empty. Every alignment value shall be a non-negative
      integral power of two.
    </p>
<p>
      Alignments have an order from <span class="emphasis"><em>weaker</em></span> to <span class="emphasis"><em>stronger</em></span>
      or <span class="emphasis"><em>stricter</em></span> alignments. Stricter alignments have larger
      alignment values. An address that satisfies an alignment requirement also satisfies
      any weaker valid alignment requirement.
    </p>
<p>
      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
      <code class="computeroutput"><span class="keyword">char</span></code>, <code class="computeroutput"><span class="keyword">signed</span>
      <span class="keyword">char</span></code>, and <code class="computeroutput"><span class="keyword">unsigned</span>
      <span class="keyword">char</span></code> shall have the weakest alignment
      requirement. [<span class="emphasis"><em>Note:</em></span> This enables the character types to
      be used as the underlying type for an aligned memory area. &#8212;<span class="emphasis"><em>end
      note</em></span>]
    </p>
<p>
      Comparing alignments is meaningful and provides the obvious results:
    </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
          Two alignments are equal when their numeric values are equal.
        </li>
<li class="listitem">
          Two alignments are different when their numeric values are not equal.
        </li>
<li class="listitem">
          When an alignment is larger than another it represents a stricter alignment.
        </li>
</ul></div>
<p>
      [<span class="emphasis"><em>Note:</em></span> The runtime pointer alignment function can be used
      to obtain an aligned pointer within a buffer; the aligned-storage templates
      in the library can be used to obtain aligned storage. &#8212;<span class="emphasis"><em>end
      note</em></span>]
    </p>
<p>
      If a request for a specific extended alignment in a specific context is not
      supported by an implementation, the program is ill-formed. Additionally, a
      request for runtime allocation of dynamic storage for which the requested alignment
      cannot be honored shall be treated as an allocation failure.
    </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2014-2017 Glen
      Joseph Fernandes<p>
        Distributed under the Boost Software License, Version 1.0.
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
</body>
</html>