Skip to content

Commit 17dab33

Browse files
committed
document zero-sized struct behavior
1 parent 72f5db3 commit 17dab33

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Diff for: reference/src/representation/structs-and-tuples.md

+8
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ following:
188188

189189
[^aligned]: Aligning an offset O to an alignment A means to round up the offset O until it is a multiple of the alignment A.
190190

191+
One deviation from C comes about with "empty structs". In Rust, a
192+
struct that contains (transitively) no data members is considered to
193+
have size zero, which is not something that exists in C. This includes
194+
a struct like `#[repr(C)] struct Foo { }`. Further, when a
195+
`#[repr(C)]` struct has a field whose type has zero-size, that field
196+
may induce padding due to its alignment, but will not otherwise affect
197+
the offsets of subsequent fields (as it takes up zero space).
198+
191199
The intention is that if one has a set of C struct declarations and a
192200
corresponding set of Rust struct declarations, all of which are tagged
193201
with `#[repr(C)]`, then the layout of those structs will all be

0 commit comments

Comments
 (0)