1 #include <ccan/alignof/alignof.h>
4 #include <ccan/tap/tap.h>
6 /* Alignment is remarkably difficult to test. The rules may be more
7 * complex than ALIGNOF() can know: eg. on i386 __alignof__(double) == 8, but
8 * __alignof__(struct containing double) == 4.
10 * Technically, we can only test that we give *at least* the alignment which
11 * naturally occurs, and that accesses work.
13 * For the moment, we work around double. */
27 int main(int argc, char *argv[])
29 struct lots_of_types lots_of_types, *lp = malloc(sizeof(*lp));
39 /* Make sure we use all the variables. */
44 ok1((unsigned long)&c % ALIGNOF(char) == 0);
45 ok1((unsigned long)&s % ALIGNOF(short) == 0);
46 ok1((unsigned long)&i % ALIGNOF(int) == 0);
47 ok1((unsigned long)&f % ALIGNOF(float) == 0);
48 ok1((unsigned long)&d % ALIGNOF(double) == 0);
50 ok1((unsigned long)&lots_of_types.c % ALIGNOF(char) == 0);
51 ok1((unsigned long)&lots_of_types.s % ALIGNOF(short) == 0);
52 ok1((unsigned long)&lots_of_types.i % ALIGNOF(int) == 0);
53 ok1((unsigned long)&lots_of_types.f % ALIGNOF(float) == 0);
54 ok1(offsetof(struct lots_of_types, d) % ALIGNOF(double) == 0);
56 ok1((unsigned long)&lp->c % ALIGNOF(char) == 0);
57 ok1((unsigned long)&lp->s % ALIGNOF(short) == 0);
58 ok1((unsigned long)&lp->i % ALIGNOF(int) == 0);
59 ok1((unsigned long)&lp->f % ALIGNOF(float) == 0);
60 ok1((unsigned long)&lp->d % ALIGNOF(double) == 0);