Changeset d63eeb0 for src/examples/minmax.c
- Timestamp:
- Feb 9, 2016, 3:25:05 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 7528ba1
- Parents:
- 771b3c3 (diff), bd85400 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/examples/minmax.c
r771b3c3 rd63eeb0 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // min .c --7 // minmax.c -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 4 11:40:51201613 // Update Count : 2612 // Last Modified On : Wed Feb 3 11:14:49 2016 13 // Update Count : 46 14 14 // 15 15 16 #include "fstream.h" 17 18 forall( type T | { int ?<?( T, T ); } ) 19 T min( const T t1, const T t2 ) { 20 return t1 < t2 ? t1 : t2; 21 } // min 16 #include <fstream> 17 #include <stdlib> // min, max 22 18 23 19 int main( void ) { 24 20 ofstream *sout = ofstream_stdout(); 25 // char does not have less than.21 // char does not have less or greater than. 26 22 int ?<?( char op1, char op2 ) { return (int)op1 < (int)op2; } 23 int ?>?( char op1, char op2 ) { return (int)op1 > (int)op2; } 27 24 28 25 sout | "char\t\t\t" | 'z' | ' ' | 'a' | "\tmin " | min( 'z', 'a' ) | endl; … … 36 33 sout | "double\t\t\t" | 4.0 | ' ' | 3.1 | "\tmin " | min( 4.0, 3.1 ) | endl; 37 34 sout | "long double\t\t" | 4.0l | ' ' | 3.1l | "\tmin " | min( 4.0l, 3.1l ) | endl; 35 36 sout | endl; 37 38 sout | "char\t\t\t" | 'z' | ' ' | 'a' | "\tmax " | max( 'z', 'a' ) | endl; 39 sout | "signed int\t\t" | 4 | ' ' | 3 | "\tmax " | max( 4, 3 ) | endl; 40 sout | "unsigned int\t\t" | 4u | ' ' | 3u | "\tmax " | max( 4u, 3u ) | endl; 41 sout | "signed long int\t\t" | 4l | ' ' | 3l | "\tmax " | max( 4l, 3l ) | endl; 42 sout | "unsigned long int\t" | 4ul | ' ' | 3ul | "\tmax " | max( 4ul, 3ul ) | endl; 43 sout | "signed long long int\t" | 4ll | ' ' | 3ll | "\tmax " | max( 4ll, 3ll ) | endl; 44 sout | "unsigned long long int\t" | 4ull | ' ' | 3ull | "\tmax " | max( 4ull, 3ull ) | endl; 45 sout | "float\t\t\t" | 4.0f | ' ' | 3.1f | "\tmax " | max( 4.0f, 3.1f ) | endl; 46 sout | "double\t\t\t" | 4.0 | ' ' | 3.1 | "\tmax " | max( 4.0, 3.1 ) | endl; 47 sout | "long double\t\t" | 4.0l | ' ' | 3.1l | "\tmax " | max( 4.0l, 3.1l ) | endl; 38 48 } // main 39 49 40 50 // Local Variables: // 41 51 // tab-width: 4 // 42 // compile-command: "cfa min .c fstream.o iostream.o iterator.o" //52 // compile-command: "cfa minmax.c" // 43 53 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.