2018-09-12 00:57:53 +08:00
|
|
|
const std = @import("std");
|
|
|
|
|
2018-11-13 21:08:37 +08:00
|
|
|
const B = union(enum) {
|
2018-09-12 00:57:53 +08:00
|
|
|
D: u8,
|
|
|
|
E: u16,
|
|
|
|
};
|
|
|
|
|
2018-11-13 21:08:37 +08:00
|
|
|
const A = union(enum) {
|
2018-09-12 00:57:53 +08:00
|
|
|
B: B,
|
|
|
|
C: u8,
|
|
|
|
};
|
|
|
|
|
|
|
|
test "union that needs padding bytes inside an array" {
|
2018-11-13 21:08:37 +08:00
|
|
|
var as = []A{
|
|
|
|
A{ .B = B{ .D = 1 } },
|
|
|
|
A{ .B = B{ .D = 1 } },
|
2018-09-12 00:57:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const a = as[0].B;
|
|
|
|
std.debug.assertOrPanic(a.D == 1);
|
|
|
|
}
|