Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Hejsil opened this issue Jun 14, 2019 · 1 comment
Open

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

Hejsil opened this issue Jun 14, 2019 · 1 comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@Hejsil
Copy link
Sponsor Contributor

Hejsil commented Jun 14, 2019

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´
}
@Hejsil Hejsil added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Jun 14, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone Jun 14, 2019
@andrewrk
Copy link
Member

This makes sense, but there should be a way to get the address, because there is an address associated with these pointers - it's just that you have to do some bit fiddling to get the value out. The address will be pointing to the "host integer" that contains the bits.

@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Jan 8, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 27, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

2 participants