aboutsummaryrefslogtreecommitdiff
path: root/doc/langref/runtime_incorrect_pointer_alignment.zig
blob: 3c168691bfd73727e29caa66a1425665cdc2c3e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
const mem = @import("std").mem;
pub fn main() !void {
    var array align(4) = [_]u32{ 0x11111111, 0x11111111 };
    const bytes = mem.sliceAsBytes(array[0..]);
    if (foo(bytes) != 0x11111111) return error.Wrong;
}
fn foo(bytes: []u8) u32 {
    const slice4 = bytes[1..5];
    const int_slice = mem.bytesAsSlice(u32, @as([]align(4) u8, @alignCast(slice4)));
    return int_slice[0];
}

// exe=fail