1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include <bitset>
#include <iostream>
namespace notalign {
struct toto1
{
short int Data[100];
char Reserve[15];
};
struct toto2
{
short int data[100];
bool test[80]; // pour moi, test doit occuper 10 bytes
char reserve[5];
};
struct toto3 {
short int D;
std::bitset<80> Test;
char Reserve[5];
};
}
namespace align {
#pragma pack(1)
struct toto1
{
short int Data[100];
char Reserve[15];
};
#pragma pack(1)
struct toto2
{
short int data[100];
bool test[80]; // pour moi, test doit occuper 10 bytes
char reserve[5];
};
#pragma pack(1)
struct toto3 {
short int D;
std::bitset<80> Test;
char Reserve[5];
};
}
int main() {
std::cout
<< sizeof(notalign::toto1) << "\n"
<< sizeof(notalign::toto2) << "\n"
<< sizeof(notalign::toto3) << "\n"
<< sizeof(align::toto1) << "\n"
<< sizeof(align::toto2) << "\n"
<< sizeof(align::toto3) << "\n"
<< std::endl;
return 1;
} |
Partager