source: tests/genericUnion.c @ 47ed726

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resnenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 47ed726 was 73abe95, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Replace extension-less headers with .hfa

  • Property mode set to 100644
File size: 496 bytes
Line 
1#include <limits.hfa>
2
3forall(otype T)
4union ByteView {
5        T val;
6        char bytes[(sizeof(int))]; // want to change to sizeof(T)
7};
8
9forall(otype T)
10void print(ByteView(T) x) {
11        for (int i = 0; i < sizeof(int); i++) { // want to change to sizeof(T)
12                printf("%02x", x.bytes[i] & 0xff);
13        }
14}
15
16forall(otype T)
17void f(ByteView(T) x, T val) {
18        print(x);
19        printf(" ");
20        x.val = val;
21        print(x);
22        printf("\n");
23}
24
25int main() {
26        ByteView(unsigned) u = { 0 };
27        ByteView(int) i = { 0 };
28        f(u, MAX);
29        f(i, -1);
30}
Note: See TracBrowser for help on using the repository browser.