Byte pointer in packed struct compiler error (0.17.1)

Finally went from Zig 0.15.2 to 0.17.1.

I was wondering about a new compiler error.

having this:

pub const Bgra = packed struct {
    b: u8,
    g: u8,
    r: u8,
    a: u8,
};

error: expected type ‘*u8’, found ‘*align(4:16:4) u8’
when doing tthis:

var color: Bgra = .empty; // empty not declared here but should be obbious
add(&color.a, somevalue); // What is wrong with the address?
fn add8(dst: *u8, diff: i8) void {
    dst.* +%= @bitCast(diff);
}

The cases where bit pointers can coerce to normal pointers was made more narrow, probably to avoid bugs in the current implementation.

There is an accepted proposal to improve them. Though it does not talk about coercion to normal pointers.

Ah I saw that long proposal yes.
But: it is not a bit pointer. It is a byte pointer!
I guess it does only give a compile error in this case (byte inside a packed struct)? Not with a “normal” byte.

nope it’s a bit pointer. The fact that it happens to line up with byte boundaries is irrelevant in the same way an align(4) pointer is still align 4 even if it happens to line up with align 8.

Ok I surrender :slight_smile: I kinda understand the problem and the proposal.