Skip to content

Commit 9e2f5f0

Browse files
committed
Explicitly add repr(C) in all examples
Since the feature requires `repr(C)`, the examples should reflect that.
1 parent 917e073 commit 9e2f5f0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

text/0000-unnamed-fields.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ define an unnamed grouping of overlapping fields inline within the `struct`,
7979
using the `union` keyword:
8080

8181
```rust
82+
#[repr(C)]
8283
struct S {
8384
a: u32,
8485
_: union {
@@ -106,6 +107,7 @@ mechanism, you can also define an unnamed grouping of non-overlapping fields
106107
inline within the `union`, using the `struct` keyword:
107108

108109
```rust
110+
#[repr(C)]
109111
union U {
110112
a: u32,
111113
_: struct {
@@ -128,6 +130,7 @@ unions.
128130
Unnamed fields can contain other unnamed fields. For example:
129131

130132
```rust
133+
#[repr(C)]
131134
struct S {
132135
a: u32,
133136
_: union {
@@ -150,13 +153,15 @@ following three structures:
150153

151154
```rust
152155
// variant 1
156+
#[repr(C)]
153157
struct S {
154158
a: u32,
155159
b: u32,
156160
f: u64,
157161
}
158162

159163
// variant 2
164+
#[repr(C)]
160165
struct S {
161166
a: u32,
162167
c: u16,
@@ -165,6 +170,7 @@ struct S {
165170
}
166171

167172
// variant 3
173+
#[repr(C)]
168174
struct S {
169175
a: u32,
170176
e: f32,
@@ -177,11 +183,13 @@ struct S {
177183
An unnamed field may also use a named `struct` or `union` type. For instance:
178184

179185
```rust
186+
#[repr(C)]
180187
union U {
181188
x: i64,
182189
y: f64,
183190
}
184191

192+
#[repr(C)]
185193
struct S {
186194
_: U,
187195
z: usize,
@@ -214,6 +222,7 @@ vertically, in sequence, and `union` lays out fields horizontally, overlapping
214222
with each other. The following definition:
215223

216224
```rust
225+
#[repr(C)]
217226
struct S {
218227
a: u32,
219228
_: union {
@@ -252,6 +261,7 @@ order.
252261
Given the following declaration:
253262

254263
```rust
264+
#[repr(C)]
255265
struct S {
256266
a: u32,
257267
_: union {
@@ -279,6 +289,7 @@ the fields appeared at the top level. For instance, the following code matches
279289
a discriminant and extracts the corresponding field.
280290

281291
```rust
292+
#[repr(C)]
282293
struct S {
283294
a: u32,
284295
_: union {
@@ -358,6 +369,7 @@ You cannot use this feature to define multiple fields with the same name. For
358369
instance, the following definition will produce an error:
359370

360371
```rust
372+
#[repr(C)]
361373
struct S {
362374
a: u32,
363375
_: union {

0 commit comments

Comments
 (0)