Skip to content

Commit 393ef3e

Browse files
committed
Be more explicit about the layout guarantees of integer and floating-point types.
1 parent c4c1859 commit 393ef3e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

reference/src/layout/integers-floatingpoint.md

+19
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ Note: on all platforms that Rust's currently supports, the size and alignment of
3737

3838
For full ABI compatibility details, see [Gankro’s post](https://gankro.github.io/blah/rust-layouts-and-abis/#the-layoutsabis-of-builtins).
3939

40+
## Fixed-width integer types
41+
42+
Rust's fixed-width integer types `{i,u}{8,16,32,64}` have the same layout as the
43+
C fixed-width integer types from the `<stdint.h>` header
44+
`{u,}int{8,16,32,64}_t`. That is:
45+
46+
* these types have no padding bits,
47+
* their size exactly matches their bit-width,
48+
* negative values of signed integer types are represented using `2`'s complement.
49+
50+
Therefore these integer types are safe to use directly in C FFI where the
51+
fixed-width integer types are expected.
52+
53+
## Fixed-width floating point types
54+
55+
Rust's `f32` and `f64` types have the same layout as C's `float` and `double`
56+
types, respectively. Therefore these floating-point types are safe to use
57+
directly in C FFI where the appropriate C types are expected.
58+
4059
## Relationship to C integer hierarchy
4160
C integers:
4261
- char: at least 8 bits

0 commit comments

Comments
 (0)