How to set a default alignment for a given struct or for the entire file ? #2373
Unanswered
f6fvy
asked this question in
Pattern Language Q&A
Replies: 1 comment 2 replies
-
Hey, there isn't a built-in way directly right now. You can wrap both your struct and the AlignTo into another struct and place that but it's still just going to insert padding before your struct and not actually align the outer struct. import std.mem;
struct Aligned<T, auto Alignment> {
std::mem::AlignTo<Alignment>;
T value;
} [[inline]];
struct ABC {
u32 x;
};
struct Test {
u8 x;
Aligned<ABC, 16> abc;
};
Test test @ 0x00; |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to apply a default alignment to all members of a struct, and/or to all members of a all struct in an entire file?
From what I understand, std::mem::AlignTo can only be used inside a structure to align the next member, but I can't find a way to apply this for all members (other than repeating it, which is quite tedious).
Beta Was this translation helpful? Give feedback.
All reactions