Skip to content

Commit 02652ba

Browse files
committed
Be more explicit about the layout guarantees of integer and floating-point types.
1 parent af01162 commit 02652ba

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
@@ -38,6 +38,25 @@ Note: on all platforms that Rust's currently supports, the size and alignment of
3838

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

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

0 commit comments

Comments
 (0)