]> pd.if.org Git - lice/blobdiff - tests/offsetof.c
autocommit for files dated 2014-11-17 20:13:36
[lice] / tests / offsetof.c
diff --git a/tests/offsetof.c b/tests/offsetof.c
new file mode 100644 (file)
index 0000000..bbc4ee0
--- /dev/null
@@ -0,0 +1,27 @@
+// offsetof
+
+#include <stddef.h>
+
+struct test {
+    int   a; // 0
+    int   b; // 4
+    int   c; // 8
+    char  d; // 12
+    short e; // 14
+    int   f; // 16
+};
+
+int main(void) {
+    expecti(offsetof(struct test, a), 0);
+    expecti(offsetof(struct test, b), 4);
+    expecti(offsetof(struct test, c), 8);
+    expecti(offsetof(struct test, d), 12);
+    expecti(offsetof(struct test, e), 14);
+    expecti(offsetof(struct test, f), 16);
+
+    // it should also be a valid integer constant expression
+    int a[offsetof(struct test, b)];
+    expecti(sizeof(a), sizeof(int) * 4);
+
+    return 0;
+}