Changeset 784deab for src/examples/square.c
- Timestamp:
- Jan 8, 2016, 10:37:10 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:
- 61f9356
- Parents:
- 1cced28
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/square.c
r1cced28 r784deab 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 27 18:43:34 201513 // Update Count : 2 12 // Last Modified On : Tue Jan 5 18:08:20 2016 13 // Update Count : 21 14 14 // 15 15 16 extern "C" { 17 #include <stdio.h> 18 } 16 #include "fstream.h" 19 17 20 18 forall( type T | { T ?*?( T, T ); } ) 21 19 T square( T t ) { 22 20 return t * t; 23 } 24 25 //char ?*?( char a1, char a2 ) { 26 // return (char)( (int)a1 * (int)a2 ); 27 //} 21 } // square 28 22 29 23 int main() { 30 char c = 5; 31 short int s = 5; 32 int i = 5; 33 float f = 5.0; 34 double d = 5.0; 35 // printf( "result of square of 5 is %d\n", (char)square( c ) ); 36 printf( "result of square of 5 is %d\n", square( s ) ); 37 printf( "result of square of 5 is %d\n", square( i ) ); 38 printf( "result of square of 5 is %f\n", square( f ) ); 39 printf( "result of square of 5 is %f\n", square( d ) ); 40 } 24 #if 0 25 ofstream *sout = ofstream_stdout(); 26 sout | "result of squaring 9 is " | endl; 27 28 // char does not have multiplication. 29 char ?*?( char a1, char a2 ) { 30 return (char)((int)a1 * (int)a2); 31 } // ?*? 32 char c = 9; 33 sout | "char\t\t\t" | square( c ) | endl; 34 35 sout | square( s ) | endl; 36 #endif 37 short int s = 9; 38 square( s ); 39 #if 0 40 signed int i = 9; 41 sout | "signed int\t\t" | square( i ) | endl; 42 43 unsigned int ui = 9; 44 sout | "unsigned int\t\t" | square( ui ) | endl; 45 46 long int li = 9; 47 sout | "signed long int\t\t" | square( li ) | endl; 48 49 unsigned long int uli = 9; 50 sout | "unsigned long int\t" | square( uli ) | endl; 51 52 signed long long int lli = 9; 53 sout | "signed long long int\t" | square( lli ) | endl; 54 55 unsigned long long int ulli = 9; 56 sout | "unsigned long long int\t" | square( ulli ) | endl; 57 58 float f = 9.0; 59 sout | "float\t\t\t" | square( f ) | endl; 60 61 double d = 9.0; 62 sout | "double\t\t\t" | square( d ) | endl; 63 64 long double ld = 9.0; 65 sout | "long double\t\t" | square( ld ) | endl; 66 #endif 67 } // main 41 68 42 69 // Local Variables: // 43 70 // tab-width: 4 // 44 // compile-command: "cfa square.c " //71 // compile-command: "cfa square.c fstream.o iostream.o iterator.o" // 45 72 // End: //
Note: See TracChangeset
for help on using the changeset viewer.