source: tests/genericUnion.cfa @ d62806c

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since d62806c was d5b2ac8, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

formatting

  • Property mode set to 100644
File size: 1.0 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// genericUnion.cfa --
8//
9// Author           : Peter A. Buhr
10// Created On       : Tue Dec 25 14:42:46 2018
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Tue Dec 25 14:46:33 2018
13// Update Count     : 2
14//
15
16#include <limits.hfa>
17
18forall(otype T)
19union ByteView {
20        T val;
21        char bytes[(sizeof(int))];                                                      // want to change to sizeof(T)
22};
23
24forall(otype T)
25void print(ByteView(T) x) {
26        for (int i = 0; i < sizeof(int); i++) {                         // want to change to sizeof(T)
27                printf("%02x", x.bytes[i] & 0xff);
28        }
29}
30
31forall(otype T)
32void f(ByteView(T) x, T val) {
33        print(x);
34        printf(" ");
35        x.val = val;
36        print(x);
37        printf("\n");
38}
39
40int main() {
41        ByteView(unsigned) u = { 0 };
42        ByteView(int) i = { 0 };
43        f(u, MAX);
44        f(i, -1);
45}
46
47// Local Variables: //
48// tab-width: 4 //
49// compile-command: "cfa genericUnion.cfa" //
50// End: //
Note: See TracBrowser for help on using the repository browser.