From 1b8fbbd843ddeb5fc81c9303db9c590a436d499b Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 9 Jul 2018 12:10:32 -0700 Subject: progress --- ccan/alignof/_info | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 ccan/alignof/_info (limited to 'ccan/alignof/_info') diff --git a/ccan/alignof/_info b/ccan/alignof/_info new file mode 100644 index 0000000..ee2b7ad --- /dev/null +++ b/ccan/alignof/_info @@ -0,0 +1,51 @@ +#include "config.h" +#include +#include + +/** + * alignof - ALIGNOF() macro to determine alignment of a type. + * + * Many platforms have requirements that certain types must be aligned + * to certain address boundaries, such as ints needing to be on 4-byte + * boundaries. Attempting to access variables with incorrect + * alignment may cause performance loss or even program failure (eg. a + * bus signal). + * + * There are times which it's useful to be able to programatically + * access these requirements, such as for dynamic allocators. + * + * Example: + * #include + * #include + * #include + * + * // Output contains "ALIGNOF(char) == 1" + * // Will also print out whether an onstack char array can hold a long. + * int main(void) + * { + * char arr[sizeof(int)]; + * + * printf("ALIGNOF(char) == %zu\n", ALIGNOF(char)); + * if ((unsigned long)arr % ALIGNOF(int)) { + * printf("arr %p CANNOT hold an int\n", arr); + * exit(1); + * } else { + * printf("arr %p CAN hold an int\n", arr); + * exit(0); + * } + * } + * + * License: CC0 (Public domain) + * Author: Rusty Russell + */ +int main(int argc, char *argv[]) +{ + if (argc != 2) + return 1; + + if (strcmp(argv[1], "depends") == 0) { + return 0; + } + + return 1; +} -- cgit v1.2.3