source: src/examples/swap.c@ 7528ba1

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 7528ba1 was bd85400, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

remove offsetof keyword, parser 0/1 names as structure fields, update examples to new stdlib, rename algorithms to stdlib, extend stdlib, use correct type for box parameters

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