summaryrefslogtreecommitdiff
path: root/ccan/alignof/alignof.h
diff options
context:
space:
mode:
authorWilliam Casarin <jb55@jb55.com>2018-07-09 12:10:32 -0700
committerWilliam Casarin <jb55@jb55.com>2018-07-09 12:10:32 -0700
commit1b8fbbd843ddeb5fc81c9303db9c590a436d499b (patch)
treea7227dfe8e4fbaee7b1e0b58b24994dce8078f3f /ccan/alignof/alignof.h
parent37a9cdd2e80386f2c94e14e4f511284ae14c745a (diff)
progress
Diffstat (limited to 'ccan/alignof/alignof.h')
-rw-r--r--ccan/alignof/alignof.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/ccan/alignof/alignof.h b/ccan/alignof/alignof.h
new file mode 100644
index 0000000..9a02f18
--- /dev/null
+++ b/ccan/alignof/alignof.h
@@ -0,0 +1,20 @@
+/* CC0 (Public domain) - see LICENSE file for details */
+#ifndef CCAN_ALIGNOF_H
+#define CCAN_ALIGNOF_H
+#include "config.h"
+
+/**
+ * ALIGNOF - get the alignment of a type
+ * @t: the type to test
+ *
+ * This returns a safe alignment for the given type.
+ */
+#if HAVE_ALIGNOF
+/* A GCC extension. */
+#define ALIGNOF(t) __alignof__(t)
+#else
+/* Alignment by measuring structure padding. */
+#define ALIGNOF(t) ((char *)(&((struct { char c; t _h; } *)0)->_h) - (char *)0)
+#endif
+
+#endif /* CCAN_ALIGNOF_H */