source: tests/tuple/tupleAssign.cfa @ c565d68

Last change on this file since c565d68 was 57ccff1, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Missed printing change

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[33a7b6d]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 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// tupleAssign.c --
8//
9// Author           : Rob Schluntz
10// Created On       : Tue Nov 15 17:24:32 2016
[7fe2498]11// Last Modified By : Peter A. Buhr
[200fcb3]12// Last Modified On : Tue Dec  4 22:03:48 2018
13// Update Count     : 35
[33a7b6d]14//
15
[73abe95]16#include <fstream.hfa>
[7fe2498]17
[a29be37]18int main() {
19        {
20                // test multiple assignment and cascading assignment
21                int u = 5, v = 6, x = 10, y = 11;
22                [int, int] z = [100, 200];
23
24                // swap x, y and store the new [x, y] in [u, v] and in z;
[7fe2498]25                printf( "u=%d v=%d x=%d y=%d z=[%d, %d]\n", u, v, x, y, z );
[200fcb3]26                sout | "u=" | u | "v=" | v | "x=" | x | "y=" | y | "z=[" | z | "]";
[a29be37]27                z = [u, v] = [x, y] = [y, x];
[7fe2498]28                printf( "u=%d v=%d x=%d y=%d z=[%d, %d]\n", u, v, x, y, z );
[200fcb3]29                sout | "u=" | u | "v=" | v | "x=" | x | "y=" | y | "z=[" | z | "]";
[a29be37]30
31                // shuffle elements -- v = z.0, z.0 = z.1, z.1 = u, u = v
32                [v, z, u] = [z, u, v];
[7fe2498]33                printf( "u=%d v=%d z=[%d, %d]\n", u, v, z );
[200fcb3]34                sout | "u=" | u | "v=" | v | "z=[" | z | "]";
[a29be37]35
36                // multiple assignment with tuple expression on right
37                z = [111, 222];
38                [u, v] = [123, 456];
[7fe2498]39                printf( "u=%d v=%d z=[%d, %d]\n", u, v, z );
[200fcb3]40                sout | "u=" | u | "v=" | v | "z=[" | z | "]";
[a29be37]41        }
42        {
43                // test mass assignment
44                double d = 0.0;
45                int i = 0;
[0df64de]46                signed char c = '\0';
[a29be37]47                struct X {
48                        int z;
49                } x;
[9c7317c]50                X ?=?(X & x, double d) { return x; }
[a29be37]51                [int, double, int] t;
52
53                // no conversion from X to integral types, so this serves as a santiy
54                // check that as long as this compiles, ?=?(_, x) is not generated.
[7fe2498]55                [t, x, d, i, c, x] = (double)94.12;
56                printf( "d=%lg i=%d c=%c t=[%d, %lg, %d]\n", d, i, (int)c, t );
[57ccff1]57                sout | "d=" | d | "i=" | i | "c=" | (char)c | ' ' | "t=[" | t | "]";
[7fe2498]58                [x, c, i, d, x, t] = (double)-94.12;
59                printf( "d=%lg i=%d c=%c t=[%d, %lg, %d]\n", d, i, c, t );
[57ccff1]60                sout | "d=" | d | "i=" | i | "c=" | (char)c | ' ' | "t=[" | t | "]";
[a29be37]61        }
62}
[33a7b6d]63
64// Local Variables: //
65// tab-width: 4 //
66// End: //
Note: See TracBrowser for help on using the repository browser.