Verifying types have well defined memory layout

Hai, I’m not sure if I’m using this category correctly so please tell me if I should change it to help.

I was wondering if there is some way to verify if a type has well defined memory layout. I can intuit the majority of cases, but instead of intuition I’d like a somewhat more robust way to verify.

Specifically some cases with slices/arrays/vectors I’m uncertain about, would the below be valid or a compiler implementation detail? and how would I check?

comptime {
    assert(native_endian == .little);
}

fn writeToDisk(slice: []const u24, w: *Writer) !void {
    try w.writeAll(@ptrCast(slice));
}

fn readFromDisk(slice: []u24 r: *Reader) !void {
    try r.readSliceAll(@ptrCast(slice));
} 
1 Like

The relevant content here may be helpful.