Changeset 2b9ddf2
 Timestamp:
 Jan 26, 2018, 11:46:44 AM (6 years ago)
 Branches:
 ADT, aaronthesis, armeh, astexperimental, cleanupdtors, deferred_resn, demangler, enum, forallpointerdecay, jacob/cs343translation, jenkinssandbox, master, newast, newastuniqueexpr, newenv, no_list, persistentindexer, pthreademulation, qualifiedEnum, resolvnew, with_gc
 Children:
 f4a6101
 Parents:
 728df66
 Location:
 src/tests
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

src/tests/.expect/sum.txt
r728df66 r2b9ddf2 4 4 sum from 0.5 to 1.5 is 9.5, check 9.5 5 5 sum from 5 to 15 is 95 95, check 95 95 6 sum from 5 to 15 is 95, check 95 
src/tests/sum.c
r728df66 r2b9ddf2 11 11 // Created On : Wed May 27 17:56:53 2015 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Thu Dec 7 09:13:36 201714 // Update Count : 2 6113 // Last Modified On : Fri Jan 26 11:31:02 2018 14 // Update Count : 271 15 15 // 16 16 17 17 #include <fstream> 18 #include <stdlib> 18 19 19 20 void ?{}( int & c, zero_t ) { c = 0; } … … 28 29 29 30 forall( otype T  sumable( T ) ) // use trait 30 T sum( unsigned int n, T a[] ) {31 T total = 0; // instantiate T , select 032 for ( unsigned int i = 0; i < n; i += 1 )33 total += a[i]; // select +31 T sum( unsigned int size, T a[] ) { 32 T total = 0; // instantiate T from 0 by calling constructor 33 for ( unsigned int i = 0; i < size; i += 1 ) 34 total += a[i]; // select appropriate + 34 35 return total; 35 36 } // sum … … 55 56 } // for 56 57 sout  "sum from"  low  "to"  High  "is" 57  sum( size, (unsigned char *)a )  ", check"  (int)s  endl;58  sum( size, (unsigned char *)a )  ", check"  (int)s  endl; 58 59 59 60 int s = 0, a[size], v = low; … … 63 64 } // for 64 65 sout  "sum from"  low  "to"  High  "is" 65  sum( size, (int *)a )  ", check"  (int)s  endl;66  sum( size, (int *)a )  ", check"  (int)s  endl; 66 67 67 68 float s = 0.0f, a[size], v = low / 10.0f; … … 71 72 } // for 72 73 sout  "sum from"  low / 10.0f  "to"  High / 10.0f  "is" 73  sum( size, (float *)a )  ", check"  (float)s  endl;74  sum( size, (float *)a )  ", check"  (float)s  endl; 74 75 75 76 double s = 0.0, a[size], v = low / 10.0; … … 79 80 } // for 80 81 sout  "sum from"  low / 10.0  "to"  High / 10.0  "is" 81  sum( size, (double *)a )  ", check"  (double)s  endl;82  sum( size, (double *)a )  ", check"  (double)s  endl; 82 83 83 84 struct S { int i, j; }; … … 98 99 } // for 99 100 sout  "sum from"  low  "to"  High  "is" 100  sum( size, (S *)a )  ", check"  (S)s  endl; 101  sum( size, (S *)a )  ", check"  (S)s  endl; 102 103 forall( otype Impl  sumable( Impl ) ) 104 struct GS { 105 Impl * x, * y; 106 }; 107 GS(int) gs; 108 gs.x = anew( size ); // create array storage for field 109 s = 0; v = low; 110 for ( int i = 0; i < size; i += 1, v += 1 ) { 111 s += (int)v; 112 gs.x[i] = (int)v; // set filed array in generic type 113 } // for 114 sout  "sum from"  low  "to"  High  "is" 115  sum( size, gs.x )  ", check"  (int)s  endl; // add filed array in generic type 101 116 } // main 102 117
Note: See TracChangeset
for help on using the changeset viewer.