Skip to content

Commit 13e415a

Browse files
committed
Add warning for #[repr(C)] struct alignment pseudocode
1 parent bc5c540 commit 13e415a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/type-layout.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,14 @@ for field in struct.fields_in_declaration_order() {
226226
struct.size = current_offset + padding_needed_for(current_offset, struct.alignment);
227227
```
228228

229+
<div class="warning">
230+
231+
Warning: This pseudocode uses a naive algorithm that ignores overflow issues for
232+
the sake of clarity. To perform memory layout computations in actual code, use
233+
[`Layout`].
234+
235+
</div>
236+
229237
> Note: This algorithm can produce zero-sized structs. This differs from
230238
> C where structs without data still have a size of one byte.
231239
@@ -374,3 +382,4 @@ used with any other representation.
374382
[`C`]: #the-c-representation
375383
[primitive representations]: #primitive-representations
376384
[`transparent`]: #the-transparent-representation
385+
[`Layout`]: ../std/alloc/struct.Layout.html

0 commit comments

Comments
 (0)