@@ -79,6 +79,7 @@ define an unnamed grouping of overlapping fields inline within the `struct`,
79
79
using the ` union ` keyword:
80
80
81
81
``` rust
82
+ #[repr(C )]
82
83
struct S {
83
84
a : u32 ,
84
85
_ : union {
@@ -106,6 +107,7 @@ mechanism, you can also define an unnamed grouping of non-overlapping fields
106
107
inline within the ` union ` , using the ` struct ` keyword:
107
108
108
109
``` rust
110
+ #[repr(C )]
109
111
union U {
110
112
a : u32 ,
111
113
_ : struct {
@@ -128,6 +130,7 @@ unions.
128
130
Unnamed fields can contain other unnamed fields. For example:
129
131
130
132
``` rust
133
+ #[repr(C )]
131
134
struct S {
132
135
a : u32 ,
133
136
_ : union {
@@ -150,13 +153,15 @@ following three structures:
150
153
151
154
``` rust
152
155
// variant 1
156
+ #[repr(C )]
153
157
struct S {
154
158
a : u32 ,
155
159
b : u32 ,
156
160
f : u64 ,
157
161
}
158
162
159
163
// variant 2
164
+ #[repr(C )]
160
165
struct S {
161
166
a : u32 ,
162
167
c : u16 ,
@@ -165,6 +170,7 @@ struct S {
165
170
}
166
171
167
172
// variant 3
173
+ #[repr(C )]
168
174
struct S {
169
175
a : u32 ,
170
176
e : f32 ,
@@ -177,11 +183,13 @@ struct S {
177
183
An unnamed field may also use a named ` struct ` or ` union ` type. For instance:
178
184
179
185
``` rust
186
+ #[repr(C )]
180
187
union U {
181
188
x : i64 ,
182
189
y : f64 ,
183
190
}
184
191
192
+ #[repr(C )]
185
193
struct S {
186
194
_ : U ,
187
195
z : usize ,
@@ -214,6 +222,7 @@ vertically, in sequence, and `union` lays out fields horizontally, overlapping
214
222
with each other. The following definition:
215
223
216
224
``` rust
225
+ #[repr(C )]
217
226
struct S {
218
227
a : u32 ,
219
228
_ : union {
@@ -252,6 +261,7 @@ order.
252
261
Given the following declaration:
253
262
254
263
``` rust
264
+ #[repr(C )]
255
265
struct S {
256
266
a : u32 ,
257
267
_ : union {
@@ -279,6 +289,7 @@ the fields appeared at the top level. For instance, the following code matches
279
289
a discriminant and extracts the corresponding field.
280
290
281
291
``` rust
292
+ #[repr(C )]
282
293
struct S {
283
294
a : u32 ,
284
295
_ : union {
@@ -358,6 +369,7 @@ You cannot use this feature to define multiple fields with the same name. For
358
369
instance, the following definition will produce an error:
359
370
360
371
``` rust
372
+ #[repr(C )]
361
373
struct S {
362
374
a : u32 ,
363
375
_ : union {
0 commit comments