mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
Document packed struct's backing int declaration
This commit is contained in:
parent
271d896446
commit
5b9579845d
@ -3320,6 +3320,16 @@ fn doTheTest() !void {
|
|||||||
try expect(ordered[1] == 0x12);
|
try expect(ordered[1] == 0x12);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
{#code_end#}
|
||||||
|
<p>
|
||||||
|
The backing integer is inferred from the fields' total bit width.
|
||||||
|
Optionally, it can be explicitly provided and enforced at compile time:
|
||||||
|
</p>
|
||||||
|
{#code_begin|test_err|test_missized_packed_struct|backing integer type 'u32' has bit size 32 but the struct fields have a total bit size of 24#}
|
||||||
|
test "missized packed struct" {
|
||||||
|
const S = packed struct(u32) { a: u16, b: u8 };
|
||||||
|
_ = S{ .a = 4, .b = 2 };
|
||||||
}
|
}
|
||||||
{#code_end#}
|
{#code_end#}
|
||||||
<p>
|
<p>
|
||||||
|
Loading…
Reference in New Issue
Block a user