source:
tests/genericUnion.cfa
@
ea10f64
Last change on this file since ea10f64 was abb04a4, checked in by , 13 months ago | |
---|---|
|
|
File size: 1.1 KB |
Rev | Line | |
---|---|---|
[d5b2ac8] | 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 | |
[abb04a4] | 12 | // Last Modified On : Fri Oct 20 09:13:26 2023 |
13 | // Update Count : 15 | |
[d5b2ac8] | 14 | // |
15 | ||
[abb04a4] | 16 | #include <fstream.hfa> |
[73abe95] | 17 | #include <limits.hfa> |
[240e1ff] | 18 | |
[abb04a4] | 19 | forall( T ) |
[240e1ff] | 20 | union ByteView { |
21 | T val; | |
[d5b2ac8] | 22 | char bytes[(sizeof(int))]; // want to change to sizeof(T) |
[240e1ff] | 23 | }; |
24 | ||
[fd54fef] | 25 | forall(T) |
[abb04a4] | 26 | void print( ByteView(T) x ) { |
27 | for ( i; sizeof(int) ) { // want to change to sizeof(T) | |
28 | sout | nobase( pad0( wd( 2, hex( x.bytes[i] & 0xff ) ) ) ) | nosep; | |
[240e1ff] | 29 | } |
30 | } | |
31 | ||
[fd54fef] | 32 | forall(T) |
[abb04a4] | 33 | void f( ByteView(T) x, T val ) { |
34 | print( x ); | |
35 | sout | " "; | |
[240e1ff] | 36 | x.val = val; |
[abb04a4] | 37 | print( x ); |
38 | sout | nl; | |
[240e1ff] | 39 | } |
40 | ||
41 | int main() { | |
[abb04a4] | 42 | sout | nlOff; |
[240e1ff] | 43 | ByteView(unsigned) u = { 0 }; |
44 | ByteView(int) i = { 0 }; | |
[abb04a4] | 45 | f( u, MAX ); |
46 | f( i, -1 ); | |
[240e1ff] | 47 | } |
[d5b2ac8] | 48 | |
49 | // Local Variables: // | |
50 | // tab-width: 4 // | |
51 | // compile-command: "cfa genericUnion.cfa" // | |
52 | // End: // |
Note: See TracBrowser
for help on using the repository browser.