Skip to content

Commit c66a66b

Browse files
authored
Merge pull request #396 from Manishearth/padding
Clarify padding
2 parents 9f18694 + 9198878 commit c66a66b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

reference/src/glossary.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,13 @@ requirement of 2.
207207

208208
*Padding* (of a type `T`) refers to the space that the compiler leaves between fields of a struct or enum variant to satisfy alignment requirements, and before/after variants of a union or enum to make all variants equally sized.
209209

210-
Padding can be though of as `[Pad; N]` for some hypothetical type `Pad` (of size 1) with the following properties:
210+
Padding can be thought of as the type containing secret fields of type `[Pad; N]` for some hypothetical type `Pad` (of size 1) with the following properties:
211211
* `Pad` is valid for any byte, i.e., it has the same validity invariant as `MaybeUninit<u8>`.
212212
* Copying `Pad` ignores the source byte, and writes *any* value to the target byte. Or, equivalently (in terms of Abstract Machine behavior), copying `Pad` marks the target byte as uninitialized.
213213

214+
Note that padding is a property of the *type* and not the memory: reading from the padding of an `&Foo` (by casting to a byte reference) may produce initialized values if the `&Foo` is pointing to memory that was initialized (for example, if it was originally a byte buffer initialized to `0`), but the moment you perform a typed copy out of that reference you will have uninitialized padding bytes in the copy.
215+
216+
214217
We can also define padding in terms of the [representation relation]:
215218
A byte at index `i` is a padding byte for type `T` if,
216219
for all values `v` and lists of bytes `b` such that `v` and `b` are related at `T` (let's write this `Vrel_T(v, b)`),

0 commit comments

Comments
 (0)