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