Skip to content

[WIP - #633] Offset Functions #1410

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

Merged
merged 2 commits into from
Sep 21, 2018
Merged

Conversation

raulgrell
Copy link
Contributor

For #633

I'm still looking at #1408, but I'm not sure the issue is in these functions

@andrewrk andrewrk added the work in progress This pull request is not ready for review yet. label Aug 24, 2018
@andrewrk andrewrk added this to the 0.3.0 milestone Aug 25, 2018
@andrewrk
Copy link
Member

Let me know when this is ready for review

@andrewrk andrewrk modified the milestones: 0.3.0, 0.4.0 Aug 27, 2018
@raulgrell
Copy link
Contributor Author

This is done, sorry about the delay!

@andrewrk andrewrk removed the work in progress This pull request is not ready for review yet. label Sep 7, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.3.0 Sep 7, 2018
@andrewrk andrewrk merged commit f2186e5 into ziglang:master Sep 21, 2018
assert(@ptrToInt(&a.a) - @ptrToInt(&a) == @offsetOf(A, "a"));
assert(@ptrToInt(&a.b) - @ptrToInt(&a) == @offsetOf(@typeOf(a), "b"));
assert(@ptrToInt(&a.c) - @ptrToInt(&a) == @offsetOf(@typeOf(a), "c"));
std.debug.assert(@byteOffsetOf(P, "a") == 0 and @byteOffsetOf(S, "a") == 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the compiler could reorder fields for regular structs, so it seems to me the bit and byte offset tests using S might be incorrect depending changes in the compiler or settings such as the target. The original tests using the difference of addresses seems like a better assertation.

@raulgrell
Copy link
Contributor Author

You are right, the language might reorder fields and the current test is incorrect. I think ptr to int doesnt work at comptime, so either way theres a problem. The compiler isn't doing reordering yet, so I didnt worry too much for now...

@winksaville
Copy link
Contributor

The previous tests were using ptrInt so I'd guess it should work on this case to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants