File tree 1 file changed +34
-0
lines changed 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -2250,6 +2250,40 @@ or
2250
2250
</p>
2251
2251
{#header_close#}
2252
2252
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
+
2253
2287
{#header_open|Struct Naming#}
2254
2288
<p>Since all structs are anonymous, Zig infers the type name based on a few rules.</p>
2255
2289
<ul>
You can’t perform that action at this time.
0 commit comments