-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
align_of for small structs does not give the actual alignment of pointers #21611
Comments
Comment from the source:
Unfortunately, the link does not give details of why that choice was made, as it's a surprising one to say the least. |
polish issue for 1.0 milestone, P-high. |
Hard part is figuring out the correct implementation. |
I don't see the bug here, |
@tbu- that's the point, the conveniently named "align_of" is a dangerous value to use in many situations, while E.g. C++11's alignof acts like #include<cstdio>
struct foo { char x; };
int main() {
printf("%lu\n", alignof(struct foo));
} |
I've always been confused by what the heck Similarly, the documentation on what is currently |
I think sizeof and alignof (the defaults) should do whatever C++ does. |
This removes a footgun, since it is a reasonable assumption to make that pointers to `T` will be aligned to `align_of::<T>()`. This also matches the behaviour of C/C++. `min_align_of` is now deprecated. Closes rust-lang#21611.
This removes a footgun, since it is a reasonable assumption to make that pointers to `T` will be aligned to `align_of::<T>()`. This also matches the behaviour of C/C++. `min_align_of` is now deprecated. Closes rust-lang#21611.
This removes a footgun, since it is a reasonable assumption to make that pointers to `T` will be aligned to `align_of::<T>()`. This also matches the behaviour of C/C++. `min_align_of` is now deprecated. Closes #21611.
This removes a footgun, since it is a reasonable assumption to make that pointers to `T` will be aligned to `align_of::<T>()`. This also matches the behaviour of C/C++. `min_align_of` is now deprecated. Closes rust-lang#21611.
It prints
size: 1
align: 8
alignment offset: 2
. I would expect that every value of typeT
is aligned toalign_of::<T>()
(i.e. the%
should always give 0).On x86-64, this applies to anything with alignment < 8, including
#[repr(packed)]
structs.I'm not sure it's a bug, but it does seem rather confusing.
Also, NB. this means
size_of < align_of
.(
min_align_of
acts more like I might expect.)The text was updated successfully, but these errors were encountered: