-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[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
Conversation
Let me know when this is ready for review |
ddb7104
to
09a1162
Compare
This is done, sorry about the delay! |
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); |
There was a problem hiding this comment.
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 struct
s, 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.
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... |
The previous tests were using ptrInt so I'd guess it should work on this case to. |
For #633
I'm still looking at #1408, but I'm not sure the issue is in these functions