// // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // genericUnion.cfa -- // // Author : Peter A. Buhr // Created On : Tue Dec 25 14:42:46 2018 // Last Modified By : Peter A. Buhr // Last Modified On : Fri Oct 20 09:13:26 2023 // Update Count : 15 // #include #include forall( T ) union ByteView { T val; char bytes[(sizeof(int))]; // want to change to sizeof(T) }; forall(T) void print( ByteView(T) x ) { for ( i; sizeof(int) ) { // want to change to sizeof(T) sout | nobase( pad0( wd( 2, hex( x.bytes[i] & 0xff ) ) ) ) | nosep; } } forall(T) void f( ByteView(T) x, T val ) { print( x ); sout | " "; x.val = val; print( x ); sout | nl; } int main() { sout | nlOff; ByteView(unsigned) u = { 0 }; ByteView(int) i = { 0 }; f( u, MAX ); f( i, -1 ); } // Local Variables: // // tab-width: 4 // // compile-command: "cfa genericUnion.cfa" // // End: //