summaryrefslogtreecommitdiffstats
path: root/src/alignment.c
blob: 4b0cb81582cbfacc6a6ffef60eef0f97c6c241dd (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * Simple tool to check if unaligned accesses to memory work
 * as expected
 *
 * Copyleft 2009 Sascha Hauer, <s.hauer@pengutronix.de>
 *
 *
 * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 *                   Version 2, December 2004
 *
 * Copyright (C) 2004 Sam Hocevar
 * 14 rue de Plaisance, 75014 Paris, France
 * Everyone is permitted to copy and distribute verbatim or modified
 * copies of this license document, and changing it is allowed as long
 * as the name is changed.
 *
 *           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 *  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 *
 * 0. You just DO WHAT THE FUCK YOU WANT TO.
 */

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	char space[sizeof(unsigned int)];
	char *s = space;
	unsigned int *unaligned;
	int aligned1 = 0xdeadbeef, aligned2;

	unaligned = (unsigned int *)(s + 1);

	*unaligned = aligned1;
	aligned2 = *unaligned;

	if (aligned1 != aligned2) {
		fprintf(stderr, "unaligned access failed (0x%08x != 0x%08x)\n",
				aligned1, aligned2);
		exit(1);
	}

	exit(0);
}