Changeset d3b7937 for src/examples/minmax.c
- Timestamp:
- Jan 29, 2016, 4:36:39 PM (9 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, string, with_gc
- Children:
- ae8b942
- Parents:
- f3fc8cbe
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/examples/minmax.c
rf3fc8cbe rd3b7937 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 : Thu Jan 28 22:15:14 2016 13 // Update Count : 42 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 <algorithm> 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 sout | endl; 36 sout | "char\t\t\t" | 'z' | ' ' | 'a' | "\tmax " | max( 'z', 'a' ) | endl; 37 sout | "signed int\t\t" | 4 | ' ' | 3 | "\tmax " | max( 4, 3 ) | endl; 38 sout | "unsigned int\t\t" | 4u | ' ' | 3u | "\tmax " | max( 4u, 3u ) | endl; 39 sout | "signed long int\t\t" | 4l | ' ' | 3l | "\tmax " | max( 4l, 3l ) | endl; 40 sout | "unsigned long int\t" | 4ul | ' ' | 3ul | "\tmax " | max( 4ul, 3ul ) | endl; 41 sout | "signed long long int\t" | 4ll | ' ' | 3ll | "\tmax " | max( 4ll, 3ll ) | endl; 42 sout | "unsigned long long int\t" | 4ull | ' ' | 3ull | "\tmax " | max( 4ull, 3ull ) | endl; 43 sout | "float\t\t\t" | 4.0f | ' ' | 3.1f | "\tmax " | max( 4.0f, 3.1f ) | endl; 44 sout | "double\t\t\t" | 4.0 | ' ' | 3.1 | "\tmax " | max( 4.0, 3.1 ) | endl; 45 sout | "long double\t\t" | 4.0l | ' ' | 3.1l | "\tmax " | max( 4.0l, 3.1l ) | endl; 38 46 } // main 39 47 40 48 // Local Variables: // 41 49 // tab-width: 4 // 42 // compile-command: "cfa min .c fstream.o iostream.o iterator.o" //50 // compile-command: "cfa minmax.c" // 43 51 // End: //
Note: See TracChangeset
for help on using the changeset viewer.