@@ -7,7 +7,8 @@ There's also the [unsafe code guidelines] (note that it's **NOT** normative).
7
7
8
8
This is the most important ` repr ` . It has fairly simple intent: do what C does.
9
9
The order, size, and alignment of fields is exactly what you would expect from C
10
- or C++. Any type you expect to pass through an FFI boundary should have
10
+ or C++. The type is also passed across ` extern "C" ` function call boundaries the
11
+ same way C would pass the corresponding type. Any type you expect to pass through an FFI boundary should have
11
12
` repr(C) ` , as C is the lingua-franca of the programming world. This is also
12
13
necessary to soundly do more elaborate tricks with data layout such as
13
14
reinterpreting values as a different type.
@@ -86,10 +87,14 @@ be 0. However Rust will not allow you to create an enum where two variants have
86
87
the same discriminant.
87
88
88
89
The term "fieldless enum" only means that the enum doesn't have data in any
89
- of its variants. A fieldless enum without a ` repr(u*) ` or ` repr(C) ` is
90
- still a Rust native type, and does not have a stable ABI representation.
91
- Adding a ` repr ` causes it to be treated exactly like the specified
92
- integer type for ABI purposes.
90
+ of its variants. A fieldless enum without a ` repr ` is
91
+ still a Rust native type, and does not have a stable layout or representation.
92
+ Adding a ` repr(u*) ` /` repr(i*) ` causes it to be treated exactly like the specified
93
+ integer type for layout purposes (except that the compiler will still exploit its
94
+ knowledge of "invalid" values at this type to optimize enum layout, such as when
95
+ this enum is wrapped in ` Option ` ). Note that the function call ABI for these
96
+ types is still in general unspecified, except that across ` extern "C" ` calls they
97
+ are ABI-compatible with C enums of the same sign and size.
93
98
94
99
If the enum has fields, the effect is similar to the effect of ` repr(C) `
95
100
in that there is a defined layout of the type. This makes it possible to
0 commit comments