Skip to content

Commit 61c089e

Browse files
frederick-vs-jatkoeppe
authored andcommitted
[intro.object] Fix alignment in example
Makes the storage in the example properly aligned, and explicitly states size assumption.
1 parent 55b8730 commit 61c089e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

source/basic.tex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3207,6 +3207,8 @@
32073207
\end{note}
32083208
\begin{example}
32093209
\begin{codeblock}
3210+
// assumes that \tcode{sizeof(int)} is equal to 4
3211+
32103212
template<typename ...T>
32113213
struct AlignedUnion {
32123214
alignas(T...) unsigned char data[max(sizeof(T)...)];
@@ -3221,7 +3223,7 @@
32213223

32223224
struct A { unsigned char a[32]; };
32233225
struct B { unsigned char b[16]; };
3224-
A a;
3226+
alignas(int) A a;
32253227
B *b = new (a.a + 8) B; // \tcode{a.a} provides storage for \tcode{*b}
32263228
int *p = new (b->b + 4) int; // \tcode{b->b} provides storage for \tcode{*p}
32273229
// \tcode{a.a} does not provide storage for \tcode{*p} (directly),

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy