#pragma pack(push, 8)
struct A
{
char c, d;
};
#pragma pack(pop)
struct B
{
_Alignas(8) char c;
_Alignas(8) char d;
};
///////
#pragma pack(push, 1)
struct C
{
float c, d;
};
#pragma pack(pop)
/* crash, because
error: ‘_Alignas’ specifiers cannot reduce alignment of ‘c’
struct D
{
_Alignas(1) float c;
_Alignas(1) float d;
};
*/
#include <stdio.h>
int main(int argc, char** argv)
{
struct A a;
struct B b;
struct C c;
// struct D d;
printf("size of A = %llu\n", sizeof(a
)); printf("size of B = %llu\n", sizeof(b
)); printf("size of C = %llu\n", sizeof(c
)); // printf("size of D = %llu\n", sizeof(d));
return 0;
}
CgojcHJhZ21hIHBhY2socHVzaCwgOCkKc3RydWN0IEEKewoJY2hhciBjLCBkOwp9OwojcHJhZ21hIHBhY2socG9wKQoKCnN0cnVjdCBCCnsKCV9BbGlnbmFzKDgpIGNoYXIgYzsKCV9BbGlnbmFzKDgpIGNoYXIgZDsKfTsKCi8vLy8vLy8KCiNwcmFnbWEgcGFjayhwdXNoLCAxKQpzdHJ1Y3QgQwp7CglmbG9hdCBjLCBkOwp9OwojcHJhZ21hIHBhY2socG9wKQoKLyogY3Jhc2gsIGJlY2F1c2UgCiAgICAKICAgIGVycm9yOiDigJhfQWxpZ25hc+KAmSBzcGVjaWZpZXJzIGNhbm5vdCByZWR1Y2UgYWxpZ25tZW50IG9mIOKAmGPigJkKICAgIApzdHJ1Y3QgRAp7CglfQWxpZ25hcygxKSBmbG9hdCBjOwoJX0FsaWduYXMoMSkgZmxvYXQgZDsKfTsKKi8KCgojaW5jbHVkZSA8c3RkaW8uaD4KCmludCBtYWluKGludCBhcmdjLCBjaGFyKiogYXJndikKewoJc3RydWN0IEEgYTsKCXN0cnVjdCBCIGI7CglzdHJ1Y3QgQyBjOwovLwlzdHJ1Y3QgRCBkOwoJcHJpbnRmKCJzaXplIG9mIEEgPSAlbGx1XG4iLCBzaXplb2YoYSkpOwoJcHJpbnRmKCJzaXplIG9mIEIgPSAlbGx1XG4iLCBzaXplb2YoYikpOwoJcHJpbnRmKCJzaXplIG9mIEMgPSAlbGx1XG4iLCBzaXplb2YoYykpOwovLwlwcmludGYoInNpemUgb2YgRCA9ICVsbHVcbiIsIHNpemVvZihkKSk7CgkKCXJldHVybiAwOwp9