Skip to content

Commit d9598f5

Browse files
committed
clarify that #[repr(C)] matches *default* settings of C compiler
fix a few other nits too
1 parent e2edb0c commit d9598f5

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

reference/src/representation/enums.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ enum SomeEnum {
2121
Variant1,
2222
Variant2,
2323
Variant3,
24+
}
2425
```
2526

2627
Such enums correspond quite closely with enums in the C language
@@ -132,8 +133,14 @@ enum Foo {
132133
}
133134
```
134135

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.
137144

138145
### Layout of a data-carrying enums with an explicit repr annotation
139146

@@ -317,11 +324,6 @@ using the niche value zero. This is because a valid `&u8` value can
317324
never be zero, so if we see a zero value, we know that this must be
318325
`None` variant.
319326
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-
325327
**Example.** The type `Option<&u32>` will be represented at runtime as
326328
a nullable pointer. FFI interop often depends on this property.
327329

0 commit comments

Comments
 (0)