test_packed_struct_field_address.zig (416B) - Raw
1 const std = @import("std"); 2 const expect = std.testing.expect; 3 4 const BitField = packed struct { 5 a: u3, 6 b: u3, 7 c: u2, 8 }; 9 10 var bit_field = BitField{ 11 .a = 1, 12 .b = 2, 13 .c = 3, 14 }; 15 16 test "pointers of sub-byte-aligned fields share addresses" { 17 try expect(@intFromPtr(&bit_field.a) == @intFromPtr(&bit_field.b)); 18 try expect(@intFromPtr(&bit_field.a) == @intFromPtr(&bit_field.c)); 19 } 20 21 // test