Skip to content

Add compiler error for using @ptrToInt on bit aligned pointer #2677

Open
@Hejsil

Description

@Hejsil

Since bit aligned pointers is represented as meta data on the pointer type at compile time, it doesn't make sense to allow @ptrToInt on these pointers, as the address cannot be represented at runtime.

const A = packed struct {
    a: u4,
    b: u4
};

test \"\" {
    var a: A = undefined;
    _ = @ptrToInt(&a.a); // This is ok. a.a is on a byte bound so we can have a runtime address to it
    _ = @ptrToInt(&a.b); // This should be an error. The address this will return is actually the address to ´a.a´
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions