X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftcon%2F_info;h=50dc0a5cbe785927feb833a3382007b0a21478e6;hp=67923a0aecf61f497d38857bc492bb67eb7cde6a;hb=88ed9bfe13c4bd2c72b0a2513cecf9ec0f19b792;hpb=5c451bbbed80e3bcb1f6be4301026ece01ab1309 diff --git a/ccan/tcon/_info b/ccan/tcon/_info index 67923a0a..50dc0a5c 100644 --- a/ccan/tcon/_info +++ b/ccan/tcon/_info @@ -1,4 +1,5 @@ #include "config.h" +#include #include /** @@ -8,7 +9,55 @@ * is then a set of macros which check the type canary before calling * the generic routines. * - * License: Public domain + * Example: + * #include + * #include + * + * // A simple container class. Can only contain one thing though! + * struct container { + * void *contents; + * }; + * static inline void container_add_raw(struct container *c, void *p) + * { + * c->contents = p; + * } + * static inline void *container_get_raw(struct container *c) + * { + * return c->contents; + * } + * + * // This lets the user define their container type; includes a + * // "type canary" to check types against. + * #define DEFINE_TYPED_CONTAINER_STRUCT(name, type) \ + * struct name { struct container raw; TCON(type canary); } + * + * // These macros make sure the container type and pointer match. + * #define container_add(c, p) \ + * container_add_raw(&tcon_check((c), canary, (p))->raw, (p)) + * #define container_get(c) \ + * tcon_cast((c), canary, container_get_raw(&(c)->raw)) + * + * // Now, let's define two different containers. + * DEFINE_TYPED_CONTAINER_STRUCT(int_container, int *); + * DEFINE_TYPED_CONTAINER_STRUCT(string_container, char *); + * + * int main(int argc, char *argv[]) + * { + * struct int_container ic; + * struct string_container sc; + * + * // We would get a warning if we used the wrong types... + * container_add(&ic, &argc); + * container_add(&sc, argv[argc-1]); + * + * printf("Last arg is %s of %i arguments\n", + * container_get(&sc), *container_get(&ic) - 1); + * return 0; + * } + * // Given "foo" outputs "Last arg is foo of 1 arguments\n" + * // Given "foo bar" outputs "Last arg is bar of 2 arguments\n" + * + * License: CC0 (Public domain) * * Author: Rusty Russell */ @@ -22,5 +71,10 @@ int main(int argc, char *argv[]) return 0; } + if (strcmp(argv[1], "testdepends") == 0) { + printf("ccan/build_assert\n"); + return 0; + } + return 1; }