I'm trying to understand how pointer alignment works with a simple example that will demonstrate me what it does:
pub fn main() !void {
var buf1: [10]u8 = undefined;
assert(@sizeOf(@TypeOf(buf1)) == 10);
@memset(&buf1, '\x30'); // fill up with '0'
// here I'm trying to create a "sparsed" array, namely
// the one with 1 byte padding after every u8 element.
var buf2: [10]align(2) u8 = undefined;
// I know it doesn't work because align keywords applies only
// to pointers. So, what should I do? Should I restructure the data itself?
// [10]struct{elm: u8, pad: u8} ?
@memcpy(&buf2, &buf1); // fill up a sparsed one
std.log.debug("{s}", .{@as([20]u8, buf2)}); // see what's inside, including padding
}
The question in the comments.