Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upalign_of for small structs does not give the actual alignment of pointers #21611
Comments
huonw
added
the
I-nominated
label
Jan 25, 2015
This comment has been minimized.
This comment has been minimized.
|
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. |
brson
added
the
E-easy
label
Jan 29, 2015
This comment has been minimized.
This comment has been minimized.
|
polish issue for 1.0 milestone, P-high. |
pnkfelix
added
the
P-medium
label
Jan 29, 2015
pnkfelix
added this to the 1.0 milestone
Jan 29, 2015
pnkfelix
removed
the
I-nominated
label
Jan 29, 2015
This comment has been minimized.
This comment has been minimized.
|
Hard part is figuring out the correct implementation. |
This comment has been minimized.
This comment has been minimized.
|
I don't see the bug here, |
This comment has been minimized.
This comment has been minimized.
|
@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));
} |
This comment has been minimized.
This comment has been minimized.
|
I've always been confused by what the heck Similarly, the documentation on what is currently |
pnkfelix
assigned
huonw
Apr 2, 2015
This comment has been minimized.
This comment has been minimized.
|
I think sizeof and alignof (the defaults) should do whatever C++ does. |
huonw commentedJan 25, 2015
It prints
size: 1align: 8alignment offset: 2. I would expect that every value of typeTis 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_ofacts more like I might expect.)