summaryrefslogtreecommitdiff
path: root/spec/compiler.h
diff options
context:
space:
mode:
authorHanjie Wu <hanjiew@andrew.cmu.edu>2023-04-18 02:21:10 -0400
committerHanjie Wu <hanjiew@andrew.cmu.edu>2023-04-18 02:21:10 -0400
commitc71294cdd3581c3738d24ffd65414f8644a1094d (patch)
treec86245d50fad9eee4163dbba169bd1839edbf88f /spec/compiler.h
initial commit
Diffstat (limited to 'spec/compiler.h')
-rw-r--r--spec/compiler.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/compiler.h b/spec/compiler.h
new file mode 100644
index 0000000..b626f1a
--- /dev/null
+++ b/spec/compiler.h
@@ -0,0 +1,23 @@
+/** @file spec/compiler.h
+ * @brief Useful macros. Inspired by Linux compiler*.h and kernel.h.
+ * @author bblum S2011
+ */
+
+#ifndef _SPEC_COMPILER_H
+#define _SPEC_COMPILER_H
+
+/* Function annotations */
+#ifndef NORETURN
+#define NORETURN __attribute__((__noreturn__))
+#endif
+
+#define MUST_CHECK __attribute__((__warn_unused_result__))
+
+/* Force a compilation error if condition is false */
+#define STATIC_ZERO_ASSERT(condition) switch(0){case 0:case (condition):;}
+#define STATIC_NULL_ASSERT(condition) STATIC_ZERO_ASSERT(condition)
+
+/* Force a compilation error if condition is false */
+#define STATIC_ASSERT(condition) STATIC_ZERO_ASSERT(condition)
+
+#endif /* !_SPEC_COMPILER_H */