summaryrefslogtreecommitdiffstats
path: root/ccan/ccan/build_assert/_info
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-07-14 18:53:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-07-14 18:53:09 +0000
commit3945f3269b3e2763faa1ab22d225ca4dd1856b82 (patch)
tree7e96ec768baa3807ce3a1076a74037a287f4caa8 /ccan/ccan/build_assert/_info
parentInitial commit. (diff)
downloadlibnvme-c5db69fa99ba733bb136fc2b6fbb4961839f27ea.tar.xz
libnvme-c5db69fa99ba733bb136fc2b6fbb4961839f27ea.zip
Adding upstream version 1.0.upstream/1.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ccan/ccan/build_assert/_info')
-rw-r--r--ccan/ccan/build_assert/_info49
1 files changed, 49 insertions, 0 deletions
diff --git a/ccan/ccan/build_assert/_info b/ccan/ccan/build_assert/_info
new file mode 100644
index 0000000..97ebe6c
--- /dev/null
+++ b/ccan/ccan/build_assert/_info
@@ -0,0 +1,49 @@
+#include "config.h"
+#include <stdio.h>
+#include <string.h>
+
+/**
+ * build_assert - routines for build-time assertions
+ *
+ * This code provides routines which will cause compilation to fail should some
+ * assertion be untrue: such failures are preferable to run-time assertions,
+ * but much more limited since they can only depends on compile-time constants.
+ *
+ * These assertions are most useful when two parts of the code must be kept in
+ * sync: it is better to avoid such cases if possible, but seconds best is to
+ * detect invalid changes at build time.
+ *
+ * For example, a tricky piece of code might rely on a certain element being at
+ * the start of the structure. To ensure that future changes don't break it,
+ * you would catch such changes in your code like so:
+ *
+ * Example:
+ * #include <stddef.h>
+ * #include <ccan/build_assert/build_assert.h>
+ *
+ * struct foo {
+ * char string[5];
+ * int x;
+ * };
+ *
+ * static char *foo_string(struct foo *foo)
+ * {
+ * // This trick requires that the string be first in the structure
+ * BUILD_ASSERT(offsetof(struct foo, string) == 0);
+ * return (char *)foo;
+ * }
+ *
+ * License: CC0 (Public domain)
+ * Author: Rusty Russell <rusty@rustcorp.com.au>
+ */
+int main(int argc, char *argv[])
+{
+ if (argc != 2)
+ return 1;
+
+ if (strcmp(argv[1], "depends") == 0)
+ /* Nothing. */
+ return 0;
+
+ return 1;
+}