]> git.ozlabs.org Git - ccan/blobdiff - ccan/alignof/alignof.h
Move modules to ccan/ tools to tools/
[ccan] / ccan / alignof / alignof.h
diff --git a/ccan/alignof/alignof.h b/ccan/alignof/alignof.h
new file mode 100644 (file)
index 0000000..d146e4c
--- /dev/null
@@ -0,0 +1,19 @@
+#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 */