@@ -21,6 +21,7 @@ enum SomeEnum {
21
21
Variant1 ,
22
22
Variant2 ,
23
23
Variant3 ,
24
+ }
24
25
```
25
26
26
27
Such enums correspond quite closely with enums in the C language
@@ -132,8 +133,14 @@ enum Foo {
132
133
}
133
134
```
134
135
135
- ** Unresolved question:** What about platforms where ` -fshort-enums `
136
- are the default? Do we know/care about that?
136
+ ** Note:** some C compilers offer flags (e.g., ` -fshort-enums ` ) that
137
+ change the layout of enums from the default settings that are standard
138
+ for the platform. The integer size selected by ` #[repr(C)] ` is defined
139
+ to match the ** default** settings for a given target, when no such
140
+ flags are supplied. If interop with code that uses other flags is
141
+ desired, then one should either specify the sizes of enums manually or
142
+ else use an alternate target definition that is tailored to the
143
+ compiler flags in use.
137
144
138
145
### Layout of a data-carrying enums with an explicit repr annotation
139
146
@@ -317,11 +324,6 @@ using the niche value zero. This is because a valid `&u8` value can
317
324
never be zero, so if we see a zero value, we know that this must be
318
325
`None` variant.
319
326
320
- In order for the optimization to apply, the payload type must define a
321
- number of niches greater than or equal to the number of unit variants.
322
- In the case of `Option<T>`, this means that any niche at all will
323
- suffice, as there is only one unit variant (`None`).
324
-
325
327
**Example.** The type `Option<&u32>` will be represented at runtime as
326
328
a nullable pointer. FFI interop often depends on this property.
327
329
0 commit comments