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 upRFC: Add #[repr(pack = "N")] #1399
Conversation
retep998
added some commits
Dec 7, 2015
cmr
reviewed
Dec 7, 2015
| * Packing values must be a power of two. | ||
|
|
||
| By specifying this attribute, the alignment of the struct would be the smaller | ||
| of the specified packing and the default alignment of the struct otherwise. The |
This comment has been minimized.
This comment has been minimized.
cmr
reviewed
Dec 7, 2015
| # Drawbacks | ||
| [drawbacks]: #drawbacks | ||
|
|
||
| This would unfortunately make my life easier even though one of the unstated |
This comment has been minimized.
This comment has been minimized.
cmr
reviewed
Dec 7, 2015
| # Unresolved questions | ||
| [unresolved]: #unresolved-questions | ||
|
|
||
| * The behavior specified here should match the behavior of MSVC at least. Does |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
retep998
Dec 7, 2015
Author
Member
Specifically clang or gcc on a platform other than Windows. On Windows they are supposed to match the msvc ABI.
cmr
reviewed
Dec 7, 2015
|
|
||
| * The behavior specified here should match the behavior of MSVC at least. Does | ||
| it match the behavior of other C/C++ compilers as well? | ||
| * Should it still be safe to borrow fields whose alignment is less than or equal |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
The feature is necessary. If this behavior is in line with common C compilers, |
cmr
reviewed
Dec 7, 2015
| [motivation]: #motivation | ||
|
|
||
| Many C/C++ compilers allow a packing to be specified for structs which | ||
| effectivally lowers the alignment for a struct and its fields (for example with |
This comment has been minimized.
This comment has been minimized.
cmr
reviewed
Dec 7, 2015
| effectivally lowers the alignment for a struct and its fields (for example with | ||
| MSVC there is `#pragma pack(N)`). Such packing is used extensively in certain | ||
| C/C++ libraries (such as Windows API which uses it all over the place making | ||
| writing Rust libraries such as `winapi` a nightmare). |
This comment has been minimized.
This comment has been minimized.
cmr
reviewed
Dec 7, 2015
| Many C/C++ compilers allow a packing to be specified for structs which | ||
| effectivally lowers the alignment for a struct and its fields (for example with | ||
| MSVC there is `#pragma pack(N)`). Such packing is used extensively in certain | ||
| C/C++ libraries (such as Windows API which uses it all over the place making |
This comment has been minimized.
This comment has been minimized.
cmr
reviewed
Dec 7, 2015
| fill in padding which is a burdensome task. Even then that isn't quite right | ||
| because the overall alignment of the struct would end up as 1 even though it | ||
| needs to be N (or the default if that is smaller than N), so this fills in a gap | ||
| which is basically impossible to do in Rust at the moment. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
DanielKeep
commented
Dec 7, 2015
|
For reference, here's an example of Clang doing this. |
retep998
added some commits
Dec 7, 2015
This comment has been minimized.
This comment has been minimized.
|
See this comment for an interesting interaction edge case with the alignment RFC regarding required alignment. |
nrc
added
T-lang
T-compiler
labels
Dec 8, 2015
nikomatsakis
self-assigned this
Dec 17, 2015
This comment has been minimized.
This comment has been minimized.
|
Hear ye, hear ye! This RFC is now entering final comment period. |
nikomatsakis
added
the
final-comment-period
label
Apr 8, 2016
This comment has been minimized.
This comment has been minimized.
|
This seems right to have. I think the best is |
This comment has been minimized.
This comment has been minimized.
|
@ubsan It could become valid with #1559, though, or as @nrc mentions in a comment, the procedural macros RFC. |
This comment has been minimized.
This comment has been minimized.
|
I don't mind the syntax either way, as long as I can have this attribute at all. |
This comment has been minimized.
This comment has been minimized.
Dr-Emann
commented on 64f6229
Apr 11, 2016
|
Can't you force an alignment with a |
This comment has been minimized.
This comment has been minimized.
|
@Dr-Emann That doesn't work with |
This comment has been minimized.
This comment has been minimized.
starkat99
commented
Apr 13, 2016
|
I think it should just extend |
This comment has been minimized.
This comment has been minimized.
|
Hmm, I think I too prefer |
This comment has been minimized.
This comment has been minimized.
|
One area the RFC did not (explicitly) address -- or I missed it -- is what to do if there are multiple Is there any reason one might want multiple specifiers? Like, independent macros might add tighter and tighter requirements? (However, unlike with alignment, it's not obvious to me whether you would want the max or min packing that was specified.) |
This comment has been minimized.
This comment has been minimized.
|
I think if we did allow specifying the packing multiple times, that the right thing to do would be to use the smallest packing specified. The alignment of any given field is As for the align RFC, there'd need to be a decision on how it interacts with packing. Whether it does the msvc style |
This comment has been minimized.
This comment has been minimized.
|
Huzzah! The @rust-lang/lang team has decided to accept this RFC, with the caveat that the attribute be renamed to We discussed a few other things:
|
nikomatsakis
referenced this pull request
Apr 22, 2016
Closed
`#[repr(packed(N))]` (tracking issue for RFC 1399) #33158
This comment has been minimized.
This comment has been minimized.
|
Tracking issue: rust-lang/rust#33158 If you'd like to keep following the development of this feature, please subscribe to that issue, thanks! :) |
retep998 commentedDec 7, 2015
Rendered