aboutsummaryrefslogtreecommitdiff
path: root/writeups/unaligned-mem/pack.c
blob: 2b39d4d1de3ed9438a21208a83535597f2736d85 (plain)
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
#include <stdio.h>
#include <stdbool.h>

#if 0
#pragma pack(1)
#endif
struct {
	unsigned a;
	bool b;
	unsigned short c;
	unsigned d;
} a;

int main(void) {
	a.a = 0xAAAAAAAA;
	a.b = true;
	a.c = 0xFFFF;
	a.d = 0x55555555;

	for (unsigned i = 1; i <= sizeof(a); i += 1) {
		printf("%02x ", ((unsigned char*)&a)[i - 1]);
		if (i % 4 == 0) {
			printf("\n");
		}
	}

	return 0;
}