// // 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 : Tue Dec 25 14:46:33 2018 // Update Count : 2 // #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 (int i = 0; i < sizeof(int); i++) { // want to change to sizeof(T) printf("%02x", x.bytes[i] & 0xff); } } forall(T) void f(ByteView(T) x, T val) { print(x); printf(" "); x.val = val; print(x); printf("\n"); } int main() { 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: //