Skip to content

Commit f8e8530

Browse files
RalfJungehuss
authored andcommitted
emphasize that the isize values matter
1 parent 833c5ac commit f8e8530

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/type-layout.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ assert_eq!(std::mem::align_of::<SizeRoundedUp>(), 4); // From a
282282
r[layout.repr.c.enum]
283283
#### `#[repr(C)]` Field-less Enums
284284

285-
For [field-less enums], the `C` representation requires the discriminant values to either all be representable by the `int` type in the target platform's C ABI, or to all be representable by the `unsigned int` type. Nevertheless, the type of the discriminant is `isize`. The size and alignment of the enum then match that of a C enum with the same discriminant values (and without a fixed underlying type).
285+
For [field-less enums], the `C` representation requires the discriminant values to either all be representable by the `int` type in the target platform's C ABI, or to all be representable by the `unsigned int` type. Nevertheless, the type of the discriminant is `isize`. The size and alignment of the enum then match that of a C enum with the same discriminant values (and without a fixed underlying type). Crucially, the equivalent C type is determined based on the discriminant values *after* they have been cast to `isize`.
286286

287287
> [!NOTE]
288288
> The enum representation in C is implementation defined, so this is really a "best guess". In particular, this may be incorrect when the C code of interest is compiled with certain flags.

0 commit comments

Comments
 (0)