X-Git-Url: https://pd.if.org/git/?p=lice;a=blobdiff_plain;f=tests%2Funion.c;fp=tests%2Funion.c;h=cb0d982522661beb9ef0d977021c595916fbd5f4;hp=0000000000000000000000000000000000000000;hb=b6a50b8be3d6a2e2d6624983f6bf1bf0c9f6802a;hpb=946bdbe1d5dd89ab671391fbe429a1c2c48ecaa7 diff --git a/tests/union.c b/tests/union.c new file mode 100644 index 0000000..cb0d982 --- /dev/null +++ b/tests/union.c @@ -0,0 +1,31 @@ +// unions + +int global = 5; +int *pointer = &global; + +int main(void) { + union { + int a; + int b; + } a = { 128 }; + + union { + char a[4]; + int b; + } b = { .b = 0 }; + + b.a[1] = 1; + + union { + char a[4]; + int b; + } c = { 0, 1, 0, 0 }; + + expecti(a.b, 128); + expecti(b.b, 256); + expecti(c.b, 256); + + expecti(*pointer, 5); + + return 0; +}