source: tests/genericUnion.cfa @ 503c350

Last change on this file since 503c350 was abb04a4, checked in by Peter A. Buhr <pabuhr@…>, 13 months ago

change genericUnion test fromt printf to sout

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[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]19forall( T )
[240e1ff]20union ByteView {
21        T val;
[d5b2ac8]22        char bytes[(sizeof(int))];                                                      // want to change to sizeof(T)
[240e1ff]23};
24
[fd54fef]25forall(T)
[abb04a4]26void 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]32forall(T)
[abb04a4]33void 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
41int 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.