#include <stdio.h>
#pragma pack(push, 1)
struct
{
int a;
short b;
} ShouldBeSixBytes;
#pragma pack(push, 8)
struct
{
int a;
short b;
} ShouldBeEightBytes;
#pragma pack(push, 4)
struct
{
char a;
short b;
} ShouldBeFourBytes;
#pragma pack()
struct
{
int a;
short b;
} ShouldBeEightBytesToo;
#pragma pack(pop)
struct
{
char a;
char b;
char c;
} ShouldBeThreeBytes;
#pragma pack(pop)
struct
{
char a;
short b;
} ShouldBeFourBytesToo;
int nerrs = 0;
static void
dotest (const char *name, int trueOrFalse)
{
if (! trueOrFalse)
++nerrs;
printf ("test %s: %s\n", name, trueOrFalse ? "passed" : "failed");
}
int main(void)
{
dotest ("push 1", sizeof (ShouldBeSixBytes) == 6);
dotest ("push 8", sizeof (ShouldBeEightBytes) == 8);
dotest ("push 4", sizeof (ShouldBeFourBytes) == 4);
dotest (" pop 8", sizeof (ShouldBeEightBytesToo) == 8);
dotest (" pop 1", sizeof (ShouldBeThreeBytes) == 3);
dotest (" pop n", sizeof (ShouldBeFourBytesToo) == 4);
return nerrs;
}