1 #include <ccan/container_of/container_of.h>
2 #include <ccan/tap/tap.h>
3 
4 struct foo {
5 	int a;
6 	char b;
7 };
8 
main(int argc,char * argv[])9 int __attribute__((const)) main(int argc, char *argv[])
10 {
11 	struct foo foo = { .a = 1, .b = 2 };
12 	int *intp = &foo.a;
13 	char *charp = &foo.b;
14 
15 	(void)argc;
16 	(void)argv;
17 
18 	plan_tests(6);
19 	ok1(container_of(intp, struct foo, a) == &foo);
20 	ok1(container_of(charp, struct foo, b) == &foo);
21 	ok1(container_of_var(intp, &foo, a) == &foo);
22 	ok1(container_of_var(charp, &foo, b) == &foo);
23 
24 	ok1(container_off(struct foo, a) == 0);
25 	ok1(container_off(struct foo, b) == offsetof(struct foo, b));
26 	return exit_status();
27 }
28