Skip to content

Commit d96a518

Browse files
committed
several fixups
1 parent d4268f9 commit d96a518

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

other-reprs.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,26 @@ the FFI boundary.
2626
* DSTs, tuples, and tagged unions are not a concept in C and as such are never
2727
FFI safe.
2828

29-
* **The drop flag will still be added**
29+
* **The [drop flag][] will still be added**
3030

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

3350

3451

@@ -40,22 +57,15 @@ byte. This may improve the memory footprint, but will likely have other
4057
negative side-effects.
4158

4259
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.
4565

4666
`repr(packed)` is not to be used lightly. Unless you have extreme requirements,
4767
this should not be used.
4868

4969
This repr is a modifier on `repr(C)` and `repr(rust)`.
5070

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

Comments
 (0)