ADTast-experimental
Last change
on this file since f23d34db was
fd54fef,
checked in by Michael Brooks <mlbrooks@…>, 4 years ago
|
Converting the project to use the new syntax for otype, dtype and ttytpe.
Changed prelude (gen), libcfa and test suite to use it. Added a simple deprecation rule of the old syntax to the parser; we might wish to support both syntaxes "officially," like with an extra CLI switch, but this measure should serve as a simple reminder for our team to try the new syntax.
|
-
Property mode set to
100644
|
File size:
1008 bytes
|
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 |
---|
| 12 | // Last Modified On : Tue Dec 25 14:46:33 2018 |
---|
| 13 | // Update Count : 2 |
---|
| 14 | // |
---|
| 15 | |
---|
[73abe95] | 16 | #include <limits.hfa> |
---|
[240e1ff] | 17 | |
---|
[fd54fef] | 18 | forall(T) |
---|
[240e1ff] | 19 | union ByteView { |
---|
| 20 | T val; |
---|
[d5b2ac8] | 21 | char bytes[(sizeof(int))]; // want to change to sizeof(T) |
---|
[240e1ff] | 22 | }; |
---|
| 23 | |
---|
[fd54fef] | 24 | forall(T) |
---|
[240e1ff] | 25 | void print(ByteView(T) x) { |
---|
[d5b2ac8] | 26 | for (int i = 0; i < sizeof(int); i++) { // want to change to sizeof(T) |
---|
[240e1ff] | 27 | printf("%02x", x.bytes[i] & 0xff); |
---|
| 28 | } |
---|
| 29 | } |
---|
| 30 | |
---|
[fd54fef] | 31 | forall(T) |
---|
[240e1ff] | 32 | void f(ByteView(T) x, T val) { |
---|
| 33 | print(x); |
---|
| 34 | printf(" "); |
---|
| 35 | x.val = val; |
---|
| 36 | print(x); |
---|
| 37 | printf("\n"); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | int main() { |
---|
| 41 | ByteView(unsigned) u = { 0 }; |
---|
| 42 | ByteView(int) i = { 0 }; |
---|
| 43 | f(u, MAX); |
---|
| 44 | f(i, -1); |
---|
| 45 | } |
---|
[d5b2ac8] | 46 | |
---|
| 47 | // Local Variables: // |
---|
| 48 | // tab-width: 4 // |
---|
| 49 | // compile-command: "cfa genericUnion.cfa" // |
---|
| 50 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.