Skip to content

Commit 3e18392

Browse files
committed
doc,langref: mention diffs of Zig and C packed structs
1 parent b261e1d commit 3e18392

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

doc/langref.html.in

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,6 +2250,40 @@ or
22502250
</p>
22512251
{#header_close#}
22522252

2253+
<p>
2254+
A Zig packed struct behaves differently when it stands alone in the memory (non-packed
2255+
location) and when it is embedded in another packed struct or union as a field (packed
2256+
location). A Zig packed struct is also not the same as a packed struct attribute in C.
2257+
The following table highlights some differences:
2258+
</p>
2259+
<div class="table-wrapper">
2260+
<table>
2261+
<caption>Differences between Zig and C packed structs</caption>
2262+
<thead>
2263+
<tr>
2264+
<th scope="col">Property</th>
2265+
<th scope="col">Zig packed struct in non-packed location</th>
2266+
<th scope="col">Zig packed struct in packed location</th>
2267+
<th scope="col">C packed struct</th>
2268+
</tr>
2269+
</thead>
2270+
<tbody>
2271+
<tr>
2272+
<th scope="row">Size</th>
2273+
<td>Size of the backing integer.</td>
2274+
<td>Total number of bits of the fields.</td>
2275+
<td>Total number of bytes of the fields.</td>
2276+
</tr>
2277+
<tr>
2278+
<th scope="row">Alignment</th>
2279+
<td>Alignment of the backing integer.</td>
2280+
<td>Can start at any bit offset.</td>
2281+
<td>1 byte.</td>
2282+
</tr>
2283+
</tbody>
2284+
</table>
2285+
</div>
2286+
22532287
{#header_open|Struct Naming#}
22542288
<p>Since all structs are anonymous, Zig infers the type name based on a few rules.</p>
22552289
<ul>

0 commit comments

Comments
 (0)