|
Last change
on this file since aa3bfc3 was abb04a4, checked in by Peter A. Buhr <pabuhr@…>, 2 years ago |
|
change genericUnion test fromt printf to sout
|
-
Property mode
set to
100644
|
|
File size:
1.1 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 : Fri Oct 20 09:13:26 2023
|
|---|
| 13 | // Update Count : 15
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #include <fstream.hfa>
|
|---|
| 17 | #include <limits.hfa>
|
|---|
| 18 |
|
|---|
| 19 | forall( T )
|
|---|
| 20 | union ByteView {
|
|---|
| 21 | T val;
|
|---|
| 22 | char bytes[(sizeof(int))]; // want to change to sizeof(T)
|
|---|
| 23 | };
|
|---|
| 24 |
|
|---|
| 25 | forall(T)
|
|---|
| 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;
|
|---|
| 29 | }
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | forall(T)
|
|---|
| 33 | void f( ByteView(T) x, T val ) {
|
|---|
| 34 | print( x );
|
|---|
| 35 | sout | " ";
|
|---|
| 36 | x.val = val;
|
|---|
| 37 | print( x );
|
|---|
| 38 | sout | nl;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | int main() {
|
|---|
| 42 | sout | nlOff;
|
|---|
| 43 | ByteView(unsigned) u = { 0 };
|
|---|
| 44 | ByteView(int) i = { 0 };
|
|---|
| 45 | f( u, MAX );
|
|---|
| 46 | f( i, -1 );
|
|---|
| 47 | }
|
|---|
| 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.