Skip to content

Commit 9c4b331

Browse files
authored
Merge pull request #230 from lzutao/patch-1
Minor raw markdown changes
2 parents 282a992 + 6e0882a commit 9c4b331

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

reference/src/layout/scalars.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Layout of scalar types
22

33
This chapter represents the consensus from issue [#9]. It documents the memory
4-
layout and considerations for `bool`, `char`, floating point types (`f{32, 64}`), and integral types (`{i,u}{8,16,32,64,128,size}`).
4+
layout and considerations for `bool`, `char`, floating point types (`f{32, 64}`),
5+
and integral types (`{i,u}{8,16,32,64,128,size}`).
56

67
These types are all scalar types, representing a single value, and have no
78
layout `#[repr()]` flags.
@@ -10,9 +11,9 @@ layout `#[repr()]` flags.
1011

1112
## `bool`
1213

13-
Rust's `bool` has the same layout as C17's` _Bool`, that is, its size and
14-
alignment are implementation-defined. Any `bool` can be cast into an integer,
15-
taking on the values 1 (`true`) or 0 (`false`).
14+
Rust's `bool` has the same layout as C17's` _Bool`, that is, its size
15+
and alignment are [implementation-defined][data-layout]. Any `bool` can be
16+
cast into an integer, taking on the values 1 (`true`) or 0 (`false`).
1617

1718
> **Note**: on all platforms that Rust's currently supports, its size and
1819
> alignment are 1, and its ABI class is `INTEGER` - see [Rust Layout and ABIs].
@@ -22,7 +23,7 @@ taking on the values 1 (`true`) or 0 (`false`).
2223
## `char`
2324

2425
Rust char is 32-bit wide and represents an [unicode scalar value]. The alignment
25-
of `char` is _implementation-defined_.
26+
of `char` is [implementation-defined][data-layout].
2627

2728
[unicode scalar value]: http://www.unicode.org/glossary/#unicode_scalar_value
2829

@@ -38,7 +39,7 @@ They have the same layout as the [pointer types] for which the pointee is
3839
`Sized`, and are layout compatible with C's `uintptr_t` and `intptr_t` types.
3940

4041
> **Note**: C99 [7.18.2.4](https://port70.net/~nsz/c/c99/n1256.html#7.18.2.4)
41-
> requires `uintptr_t` and `intptr_t` to be at least 16-bit wide. All
42+
> requires `uintptr_t` and `intptr_t` to be at least 16-bit wide. All
4243
> platforms we currently support have a C platform, and as a consequence,
4344
> `isize`/`usize` are at least 16-bit wide for all of them.
4445
@@ -48,15 +49,15 @@ They have the same layout as the [pointer types] for which the pointee is
4849
4950
> **Note**: in the current Rust implementation, the layouts of `isize` and
5051
> `usize` determine the following:
51-
>
52+
>
5253
> * the maximum size of Rust _allocations_ is limited to `isize::MAX`.
5354
> The LLVM `getelementptr` instruction uses signed-integer field offsets. Rust
5455
> calls `getelementptr` with the `inbounds` flag which assumes that field
5556
> offsets do not overflow,
5657
>
57-
> * the maximum number of elements in an array is `usize::MAX` (`[T; N:
58-
> usize]`. Only ZST arrays can probably be this large in practice, non-ZST
59-
> arrays are bound by the maximum size of Rust values,
58+
> * the maximum number of elements in an array is `usize::MAX` (`[T; N: usize]`).
59+
> Only ZST arrays can probably be this large in practice, non-ZST arrays
60+
> are bound by the maximum size of Rust values,
6061
>
6162
> * the maximum value in bytes by which a pointer can be offseted using
6263
> `ptr.add` or `ptr.offset` is `isize::MAX`.
@@ -85,7 +86,7 @@ The alignment of Rust's `{i,u}128` is _unspecified_ and allowed to change.
8586
> **Note**: While the C standard does not define fixed-width 128-bit wide
8687
> integer types, many C compilers provide non-standard `__int128` types as a
8788
> language extension. The layout of `{i,u}128` in the current Rust
88-
> implementation does **not** match that of these C types, see
89+
> implementation does **not** match that of these C types, see
8990
> [rust-lang/#54341](https://github.com/rust-lang/rust/issues/54341).
9091
9192
### Layout compatibility with C native integer types
@@ -94,7 +95,7 @@ The specification of native C integer types, `char`, `short`, `int`, `long`,
9495
... as well as their `unsigned` variants, guarantees a lower bound on their size,
9596
e.g., `short` is _at least_ 16-bit wide and _at least_ as wide as `char`.
9697

97-
Their exact sizes are _implementation-defined_.
98+
Their exact sizes are _implementation-defined_.
9899

99100
Libraries like `libc` use knowledge of this _implementation-defined_ behavior on
100101
each platform to select a layout-compatible Rust fixed-width integer type when
@@ -123,3 +124,4 @@ _implementation-defined_.
123124
> `libc::c_double` types that can be used to safely interface with C via FFI.
124125
125126
[IEEE-754]: https://en.wikipedia.org/wiki/IEEE_754
127+
[data-layout]: https://doc.rust-lang.org/nightly/reference/type-layout.html#primitive-data-layout

0 commit comments

Comments
 (0)