summaryrefslogtreecommitdiff
path: root/test/regression/packedstruct2.c
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2011-11-26 15:40:57 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2011-11-26 15:40:57 +0000
commit60b6624ae2b28ebe9fb30c2aa6115e4d5c1ab436 (patch)
treea78b0a79576773ead96a8d39902ad3a19b20ed2d /test/regression/packedstruct2.c
parent015c64c64a5a547dcef81a75a589eeaf034654cd (diff)
cparser/*: refactoring of the expansion of read-modify-write operators
cparser/PackedStructs: treat r-m-w operations over byte-swapped fields cparser/PackedStructs: allow static initialization of packed structs test/regression: more packedstruct tests git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1738 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'test/regression/packedstruct2.c')
-rw-r--r--test/regression/packedstruct2.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/test/regression/packedstruct2.c b/test/regression/packedstruct2.c
new file mode 100644
index 0000000..0c383a4
--- /dev/null
+++ b/test/regression/packedstruct2.c
@@ -0,0 +1,69 @@
+/* Initialization of packed structs */
+
+#include <stdio.h>
+
+/* Simple packing */
+
+#pragma pack(1)
+
+struct s1 { unsigned short x; int y; char z; };
+
+struct s1 s1 = { 2345, -12345678, 'x' };
+
+void test1(void)
+{
+ printf("s1 = {x = %d, y = %d, z = '%c'}\n\n", s1.x, s1.y, s1.z);
+}
+
+/* Now with byte-swapped fields */
+
+#pragma pack(1,1,1)
+
+struct s3 {
+ unsigned char x;
+ unsigned short y;
+ unsigned int z;
+ signed short v;
+ signed int w;
+ char * p;
+ unsigned int t[3];
+ unsigned char s[2];
+};
+
+struct s3 s3 = {
+ 42, 123, 456789, -333, -314159, 0,
+ { 111, 222, 333 },
+ { 'o', 'k' }
+};
+
+void test3(void)
+{
+ printf("s3 = {x = %u, y = %u, z = %u, v = %d, w = %d, p is %s, t = {%d,%d,%d}, s = {'%c','%c'}}\n\n",
+ s3.x, s3.y, s3.z, s3.v, s3.w,
+ (s3.p == 0 ? "ok" : "BAD"),
+ s3.t[0], s3.t[1], s3.t[2],
+ s3.s[0], s3.s[1]);
+}
+
+/* Back to normal */
+
+#pragma pack()
+
+struct s4 { unsigned short x; int y; double z; };
+
+struct s4 s4 = { 123, -456789, 3.14159 };
+
+void test4(void)
+{
+ printf("s4 = {x = %d, y = %d, z = %.5f}\n\n", s4.x, s4.y, s4.z);
+}
+
+/* Test harness */
+
+int main(int argc, char ** argv)
+{
+ test1();
+ test3();
+ test4();
+ return 0;
+}