source: src/tests/swap.c @ c850687

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since c850687 was 3dcd347a, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

moved some more tests to new test folder

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[86bd7c1f]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// swap.c --
8//
9// Author           : Richard C. Bilson
10// Created On       : Wed May 27 17:56:53 2015
11// Last Modified By : Peter A. Buhr
[6e991d6]12// Last Modified On : Thu Apr 21 08:10:41 2016
13// Update Count     : 69
[86bd7c1f]14//
15
[d3b7937]16#include <fstream>
[bd85400]17#include <stdlib>                                                                               // swap
[42dcae7]18
[784deab]19int main( void ) {
[5721a6d]20        char c1 = 'a', c2 = 'b';
21        sout | "char\t\t\t" | c1 | ' ' | c2 | "\t\t\tswap ";
22        swap( &c1, &c2 );
23        sout | '\t' | c1 | ' ' | c2 | endl;
24
25        signed int i1 = -1, i2 = -2;
[6e991d6]26        sout | "signed int\t\t" | i1 | i2 | "\t\t\tswap ";
[5721a6d]27        swap( &i1, &i2 );
[6e991d6]28        sout | '\t' | i1 | i2 | endl;
[5721a6d]29
30        unsigned int ui1 = 1, ui2 = 2;
[6e991d6]31        sout | "unsigned int\t\t" | ui1 | ui2 | "\t\t\tswap ";
[5721a6d]32        swap( &ui1, &ui2 );
[6e991d6]33        sout | '\t' | ui1 | ui2 | endl;
[5721a6d]34
35        signed long int li1 = -1, li2 = -2;
[6e991d6]36        sout | "signed long int\t\t" | li1 | li2 | "\t\t\tswap ";
[5721a6d]37        swap( &li1, &li2 );
[6e991d6]38        sout | '\t' | li1 | li2 | endl;
[5721a6d]39
40        unsigned long int uli1 = 1, uli2 = 2;
[6e991d6]41        sout | "unsigned long int\t" | uli1 | uli2 | "\t\t\tswap ";
[5721a6d]42        swap( &uli1, &uli2 );
[6e991d6]43        sout | '\t' | uli1 | uli2 | endl;
[5721a6d]44
45        signed long long int lli1 = -1, lli2 = -2;
[6e991d6]46        sout | "signed long long int\t" | lli1 | lli2 | "\t\t\tswap ";
[5721a6d]47        swap( &lli1, &lli2 );
[6e991d6]48        sout | '\t' | lli1 | lli2 | endl;
[5721a6d]49
50        unsigned long long int ulli1 = 1, ulli2 = 2;
[6e991d6]51        sout | "unsigned long long int\t" | ulli1 | ulli2 | "\t\t\tswap ";
[5721a6d]52        swap( &ulli1, &ulli2 );
[6e991d6]53        sout | '\t' | ulli1 | ulli2 | endl;
[5721a6d]54
55        float f1 = 1.5, f2 = 2.5;
[6e991d6]56        sout | "float\t\t\t" | f1 | f2 | "\t\t\tswap ";
[5721a6d]57        swap( &f1, &f2 );
[6e991d6]58        sout | '\t' | f1 | f2 | endl;
[5721a6d]59
60        double d1 = 1.5, d2 = 2.5;
[6e991d6]61        sout | "double\t\t\t" | d1 | d2 | "\t\t\tswap ";
[5721a6d]62        swap( &d1, &d2 );
[6e991d6]63        sout | '\t' | d1 | d2 | endl;
[5721a6d]64
65        long double ld1 = 1.5, ld2 = 2.5;
[6e991d6]66        sout | "long double\t\t" | ld1 | ld2 | "\t\t\tswap ";
[5721a6d]67        swap( &ld1, &ld2 );
[6e991d6]68        sout | '\t' | ld1 | ld2 | endl;
[5721a6d]69
70        float _Complex fc1 = 1.5f+1.5if, fc2 = 2.5f+2.5if;
[6e991d6]71        sout | "float _Complex\t\t" | fc1 | fc2 | "\tswap ";
[5721a6d]72        swap( &fc1, &fc2 );
[6e991d6]73        sout | '\t' | fc1 | fc2 | endl;
[5721a6d]74
75        double _Complex dc1 = 1.5d+1.5id, dc2 = 2.5d+2.5id;
[6e991d6]76        sout | "double _Complex\t\t" | dc1 | dc2 | "\tswap ";
[5721a6d]77        swap( &dc1, &dc2 );
[6e991d6]78        sout | '\t' | dc1 | dc2 | endl;
[5721a6d]79
80        long double _Complex ldc1 = 1.5d+1.5il, ldc2 = 2.5d+2.5il;
[6e991d6]81        sout | "long double _Complex\t" | ldc1 | ldc2 | "\tswap ";
[5721a6d]82        swap( &ldc1, &ldc2 );
[6e991d6]83        sout | '\t' | ldc1 | ldc2 | endl;
[5721a6d]84
85        struct S { int i, j; } s1 = { 1, 2 }, s2 = { 2, 1 };
[6e991d6]86        ofstream * ?|?( ofstream * os, S s ) { return os | s.i | s.j; }
87        sout | "struct S\t\t" | s1 | "," | s2 | "\t\tswap ";
[5721a6d]88        swap( &s1, &s2 );
[6e991d6]89        sout | '\t' | s1 | "," | s2 | endl;
[5721a6d]90} // main
[42dcae7]91
92// Local Variables: //
[86bd7c1f]93// tab-width: 4 //
[d3b7937]94// compile-command: "cfa swap.c" //
[42dcae7]95// End: //
Note: See TracBrowser for help on using the repository browser.