Skip to content

Commit c8fc873

Browse files
authored
Merge pull request #118 from gnzlbg/note_128_layout
Document that the 128-bit integer types are not FFI safe
2 parents 50d530e + 4adc867 commit c8fc873

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

reference/src/layout/scalars.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,25 @@ They have the same layout as the [pointer types] for which the pointee is
6363

6464
## Fixed-width integer types
6565

66-
Rust's signed and unsigned fixed-width integer types `{i,u}{8,16,32,64}` have
67-
the same layout as the C fixed-width integer types from the `<stdint.h>` header
68-
`{u,}int{8,16,32,64}_t`. That is:
66+
For all Rust's fixed-width integer types `{i,u}{8,16,32,64,128}` it holds that:
6967

7068
* these types have no padding bits,
7169
* their size exactly matches their bit-width,
7270
* negative values of signed integer types are represented using 2's complement.
7371

74-
This properties also hold for Rust's 128-bit wide `{i,u}128` integer types, but
75-
C does not expose equivalent types in `<stdint.h>`.
72+
Furthermore, Rust's signed and unsigned fixed-width integer types
73+
`{i,u}{8,16,32,64}` have the same layout the C fixed-width integer types from
74+
the `<stdint.h>` header `{u,}int{8,16,32,64}_t`. These fixed-width integer types
75+
are therefore safe to use directly in C FFI where the corresponding C
76+
fixed-width integer types are expected.
7677

77-
Rust fixed-width integer types are therefore safe to use directly in C FFI where
78-
the corresponding C fixed-width integer types are expected.
78+
The alignment of Rust's `{i,u}128` is _unspecified_ and allowed to change.
79+
80+
> **Note**: While the C standard does not define fixed-width 128-bit wide
81+
> integer types, many C compilers provide non-standard `__int128` types as a
82+
> language extension. The layout of `{i,u}128` in the current Rust
83+
> implementation does **not** match that of these C types, see
84+
> [rust-lang/#54341](https://github.com/rust-lang/rust/issues/54341).
7985
8086
### Layout compatibility with C native integer types
8187

0 commit comments

Comments
 (0)