@@ -26,9 +26,26 @@ the FFI boundary.
26
26
* DSTs, tuples, and tagged unions are not a concept in C and as such are never
27
27
FFI safe.
28
28
29
- * ** The drop flag will still be added**
29
+ * ** The [ drop flag] [ ] will still be added**
30
30
31
- * This is equivalent to ` repr(u32) ` for enums (see below)
31
+ * This is equivalent to one of ` repr(u\*) ` (see the next section) for enums. The
32
+ chosen size is the default enum size for the target platform's C ABI. Note that
33
+ enum representation in C is undefined, and this may be incorrect when the C
34
+ code is compiled with certain flags.
35
+
36
+
37
+
38
+ # repr(u8), repr(u16), repr(u32), repr(u64)
39
+
40
+ These specify the size to make a C-like enum. If the discriminant overflows the
41
+ integer it has to fit in, it will be an error. You can manually ask Rust to
42
+ allow this by setting the overflowing element to explicitly be 0. However Rust
43
+ will not allow you to create an enum where two variants have the same discriminant.
44
+
45
+ On non-C-like enums, this will inhibit certain optimizations like the null-pointer
46
+ optimization.
47
+
48
+ These reprs have no affect on a struct.
32
49
33
50
34
51
@@ -40,22 +57,15 @@ byte. This may improve the memory footprint, but will likely have other
40
57
negative side-effects.
41
58
42
59
In particular, most architectures * strongly* prefer values to be aligned. This
43
- may mean the unaligned loads are penalized (x86), or even fault (ARM). In
44
- particular, the compiler may have trouble with references to unaligned fields.
60
+ may mean the unaligned loads are penalized (x86), or even fault (some ARM chips).
61
+ For simple cases like directly loading or storing a packed field, the compiler
62
+ might be able to paper over alignment issues with shifts and masks. However if
63
+ you take a reference to a packed field, it's unlikely that the compiler will be
64
+ able to emit code to avoid an unaligned load.
45
65
46
66
` repr(packed) ` is not to be used lightly. Unless you have extreme requirements,
47
67
this should not be used.
48
68
49
69
This repr is a modifier on ` repr(C) ` and ` repr(rust) ` .
50
70
51
-
52
-
53
-
54
- # repr(u8), repr(u16), repr(u32), repr(u64)
55
-
56
- These specify the size to make a C-like enum. If the discriminant overflows the
57
- integer it has to fit in, it will be an error. You can manually ask Rust to
58
- allow this by setting the overflowing element to explicitly be 0. However Rust
59
- will not allow you to create an enum where two variants.
60
-
61
- These reprs have no affect on a struct or non-C-like enum.
71
+ [ drop flag ] : drop-flags.html
0 commit comments