次の構造体では:
struct alignas(?) test
{
int32_t f1; // 4 bytes
int8_t f2; // 1 byte
int8_t f3; // 1 byte
};
正確に6バイトになるalignas
ように使用する方法は?sizeof(test)
alignas(1)
はコンパイラ (gcc、msvc、clang) によって受け入れられません (次のようなエラー: error: requested alignment is less than minimum alignment of 4 for type 'test'
)。
アップデート。もちろん、このバリアントは問題なく動作します。
#pragma pack(push, 1)
struct alignas(?) test
{
int32_t f1; // 4 bytes
int8_t f2; // 1 byte
int8_t f3; // 1 byte
};
#pragma pack(pop)
しかし、標準の C++11/14 のみを使用して、プリプロセッサなしでそれを行う方法はありますか?