Skip to content

Commit a514afe

Browse files
authored
Be more precise about array offset in type layouts
Currently it states that the nth element has an offset of n*(size of type). I think this is assuming that people are starting at 0, but that's not really what `nth` implies. The first element has an offset of 0, but currently it implies that `n=1`, giving it a non-zero offset. This might want a larger rewording, I added the zero-case explicitly to try and be clearer.
1 parent 8f598e2 commit a514afe

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/type-layout.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ at least equal to the size and alignment of a pointer.
7171
## Array Layout
7272

7373
Arrays are laid out so that the `nth` element of the array is offset from the
74-
start of the array by `n * the size of the type` bytes. An array of `[T; n]`
75-
has a size of `size_of::<T>() * n` and the same alignment of `T`.
74+
start of the array by `(n-1) * the size of the type` bytes i.e. the `1st`
75+
element has an offset of 0. An array of `[T; n]` has a size of
76+
`size_of::<T>() * n` and the same alignment of `T`.
7677

7778
## Slice Layout
7879

0 commit comments

Comments
 (0)