Changeset ae7f1e0 for src/examples
- Timestamp:
- Feb 24, 2016, 10:38:01 AM (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:
- 61a4875
- Parents:
- c44e622 (diff), b502055 (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. - Location:
- src/examples
- Files:
-
- 2 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/abs.c
rc44e622 rae7f1e0 10 10 // Created On : Thu Jan 28 18:26:16 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 3 11:14:58201613 // Update Count : 4 312 // Last Modified On : Wed Feb 17 09:32:04 2016 13 // Update Count : 44 14 14 // 15 15 … … 18 18 19 19 int main( void ) { 20 ofstream *sout = ofstream_stdout();21 22 20 char ch = -65; 23 21 sout | "char\t\t\t" | ch | "\tabs " | abs( ch ) | endl; -
src/examples/alloc.c
rc44e622 rae7f1e0 11 11 // Created On : Wed Feb 3 07:56:22 2016 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Wed Feb 3 16:32:04201614 // Update Count : 3813 // Last Modified On : Wed Feb 17 11:43:23 2016 14 // Update Count : 40 15 15 // 16 16 … … 27 27 28 28 int main( void ) { 29 ofstream * sout = ofstream_stdout();30 31 29 size_t size = 10; 32 30 int * p; … … 100 98 free( x ); 101 99 #endif 102 free( sout );103 100 } 104 101 -
src/examples/fstream_test.c
rc44e622 rae7f1e0 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jan 26 17:11:33 201613 // Update Count : 4 212 // Last Modified On : Wed Feb 17 11:45:43 2016 13 // Update Count : 43 14 14 // 15 15 … … 17 17 18 18 int main( void ) { 19 ofstream *sout = ofstream_stdout();20 ifstream *sin = ifstream_stdin();21 19 int nombre; 22 20 sout | "Entrez un nombre, s'il vous plaît:\n"; -
src/examples/hello.c
rc44e622 rae7f1e0 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jan 26 17:11:49201613 // Update Count : 712 // Last Modified On : Wed Feb 17 12:11:45 2016 13 // Update Count : 8 14 14 // 15 15 … … 17 17 18 18 int main() { 19 ofstream *sout = ofstream_stdout();20 ifstream *sin = ifstream_stdin();21 19 sout | "Bonjour au monde!\n"; 22 20 } -
src/examples/identity.c
rc44e622 rae7f1e0 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jan 26 17:11:58201613 // Update Count : 812 // Last Modified On : Wed Feb 17 12:17:32 2016 13 // Update Count : 10 14 14 // 15 15 … … 22 22 23 23 int main() { 24 ofstream *sout = ofstream_stdout();25 24 sout | "char\t\t\t" | identity( 'z' ) | endl; 26 25 sout | "signed int\t\t" | identity( 4 ) | endl; … … 30 29 sout | "signed long long int\t" | identity( 4ll ) | endl; 31 30 sout | "unsigned long long int\t" | identity( 4ull ) | endl; 32 sout | "float\t\t\t" | identity( 4. 0f ) | endl;33 sout | "double\t\t\t" | identity( 4. 0) | endl;34 sout | "long double\t\t" | identity( 4. 0l ) | endl;31 sout | "float\t\t\t" | identity( 4.1f ) | endl; 32 sout | "double\t\t\t" | identity( 4.1 ) | endl; 33 sout | "long double\t\t" | identity( 4.1l ) | endl; 35 34 } 36 35 -
src/examples/minmax.c
rc44e622 rae7f1e0 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 3 11:14:49201613 // Update Count : 4 612 // Last Modified On : Wed Feb 17 12:17:53 2016 13 // Update Count : 47 14 14 // 15 15 … … 18 18 19 19 int main( void ) { 20 ofstream *sout = ofstream_stdout();21 20 // char does not have less or greater than. 22 21 int ?<?( char op1, char op2 ) { return (int)op1 < (int)op2; } -
src/examples/quad.c
rc44e622 rae7f1e0 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jan 26 17:13:48201613 // Update Count : 512 // Last Modified On : Wed Feb 17 12:19:24 2016 13 // Update Count : 6 14 14 // 15 15 … … 27 27 28 28 int main() { 29 ofstream *sout = ofstream_stdout();30 29 int N = 2; 31 30 sout | "result of quad of " | N | " is " | quad( N ) | endl; -
src/examples/quoted_keyword.c
rc44e622 rae7f1e0 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jan 26 17:13:58201613 // Update Count : 812 // Last Modified On : Wed Feb 17 12:19:45 2016 13 // Update Count : 9 14 14 // 15 15 … … 28 28 29 29 int main() { 30 ofstream *sout = ofstream_stdout();31 30 sout | `catch` + st.`type` + st.`struct` + `throw` | endl; 32 31 } -
src/examples/random.c
rc44e622 rae7f1e0 7 7 8 8 int main() { 9 ofstream *sout = ofstream_stdout();10 11 9 randseed( getpid() ); // set random seed 12 10 -
src/examples/square.c
rc44e622 rae7f1e0 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jan 26 17:14:16201613 // Update Count : 2 512 // Last Modified On : Wed Feb 17 12:21:58 2016 13 // Update Count : 26 14 14 // 15 15 … … 23 23 int main() { 24 24 #if 0 25 ofstream *sout = ofstream_stdout();26 25 sout | "result of squaring 9 is " | endl; 27 26 -
src/examples/sum.c
rc44e622 rae7f1e0 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Feb 5 16:47:44201613 // Update Count : 1 3912 // Last Modified On : Tue Feb 16 23:49:31 2016 13 // Update Count : 189 14 14 // 15 15 … … 33 33 34 34 // Required to satisfy sumable as char does not have addition. 35 // const char 0; 36 // char ?+?( char op1, char op2 ) { return (int)op1 + op2; } // cast forces integer addition or recursion 37 // char ++?( char *op ) { *op += 1; return *op; } 38 // char ?++( char *op ) { char temp = *op; *op += 1; return temp; } 35 const char 0; 36 char ?+?( char t1, char t2 ) { return (int)t1 + t2; } // cast forces integer addition, otherwise recursion 37 char ?+=?( char *t1, char t2 ) { *t1 = *t1 + t2; return *t1; } 38 char ++?( char *t ) { *t += 1; return *t; } 39 char ?++( char *t ) { char temp = *t; *t += 1; return temp; } 39 40 40 41 int main( void ) { 41 42 const int low = 5, High = 15, size = High - low; 42 ofstream *sout = ofstream_stdout();43 #if 044 43 45 char s = 0, a[size]; 46 char v = low; 44 char s = 0, a[size], v = low; 47 45 for ( int i = 0; i < size; i += 1, v += 1 ) { 48 46 s += v; 49 47 a[i] = v; 50 } 48 } // for 51 49 sout | "sum from " | low | " to " | High | " is " 52 50 | (int)sum( size, a ) | ", check " | (int)s | endl; 53 51 54 int s = 0, a[size]; 55 int v = low; 52 int s = 0, a[size], v = low; 56 53 for ( int i = 0; i < size; i += 1, v += 1 ) { 57 54 s += (int)v; 58 55 a[i] = (int)v; 59 } 56 } // for 60 57 sout | "sum from " | low | " to " | High | " is " 61 58 | sum( size, (int *)a ) | ", check " | (int)s | endl; 62 59 63 float s = 0.0, a[size]; 64 float v = low / 10.0; 60 float s = 0.0, a[size], v = low / 10.0; 65 61 for ( int i = 0; i < size; i += 1, v += 0.1f ) { 66 62 s += (float)v; 67 63 a[i] = (float)v; 68 } 64 } // for 69 65 sout | "sum from " | low / 10.0 | " to " | High / 10.0 | " is " 70 66 | sum( size, (float *)a ) | ", check " | (float)s | endl; 71 #endif72 double s = 0, a[size];73 double v = low / 10.0;74 67 68 double s = 0, a[size], v = low / 10.0; 75 69 for ( int i = 0; i < size; i += 1, v += 0.1 ) { 76 70 s += (double)v; 77 71 a[i] = (double)v; 78 } 72 } // for 79 73 sout | "sum from " | low / 10.0 | " to " | High / 10.0 | " is " 80 74 | sum( size, (double *)a ) | ", check " | (double)s | endl; 81 75 82 // struct S { int i, j; } sarr[size]; 83 // struct S 0 = { 0, 0 }; 84 // struct S 1 = { 1, 1 }; 85 // S ?+?( S t1, S t2 ) { S s = { t1.i + t1.j, t2.i + t2.j }; return s; } 86 // S ?+=?( S *t1, S t2 ) { *t1 = *t1 + t2; return *t1; } 87 // S ++?( S *t ) { *t += 1; return *t; } 88 // S ?++( S *t ) { S temp = *t; *t += 1; return temp; } 89 // sum( size, sarr ); 76 struct S { int i, j; } 0 = { 0, 0 }, 1 = { 1, 1 }; 77 S ?+?( S t1, S t2 ) { S s = { t1.i + t2.i, t1.j + t2.j }; return s; } 78 S ?+=?( S *t1, S t2 ) { *t1 = *t1 + t2; return *t1; } 79 S ++?( S *t ) { *t += 1; return *t; } 80 S ?++( S *t ) { S temp = *t; *t += 1; return temp; } 81 ofstream * ?|?( ofstream * os, S v ) { return os | v.i | ' ' | v.j; } 82 83 S s = 0, a[size], v = { low, low }; 84 for ( int i = 0; i < size; i += 1, v += (S)1 ) { 85 s += (S)v; 86 a[i] = (S)v; 87 } // for 88 sout | "sum from " | low | " to " | High | " is " 89 | sum( size, (S *)a ) | ", check " | (S)s | endl; 90 90 } // main 91 91 -
src/examples/swap.c
rc44e622 rae7f1e0 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 3 11:14:04201613 // Update Count : 6 312 // Last Modified On : Wed Feb 17 12:22:12 2016 13 // Update Count : 64 14 14 // 15 15 … … 18 18 19 19 int main( void ) { 20 ofstream *sout = ofstream_stdout();21 22 20 char c1 = 'a', c2 = 'b'; 23 21 sout | "char\t\t\t" | c1 | ' ' | c2 | "\t\t\tswap "; -
src/examples/twice.c
rc44e622 rae7f1e0 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jan 26 17:14:44201613 // Update Count : 1 212 // Last Modified On : Wed Feb 17 12:23:25 2016 13 // Update Count : 13 14 14 // 15 15 … … 27 27 char ?++( char *op ) { char temp = *op; *op += 1; return temp; } 28 28 29 ofstream *sout = ofstream_stdout();30 29 sout | twice( 'a' ) | ' ' | twice( 1 ) | ' ' | twice( 3.2 ) | endl; 31 30 } -
src/examples/vector_test.c
rc44e622 rae7f1e0 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jan 26 17:14:52201613 // Update Count : 1 712 // Last Modified On : Wed Feb 17 12:23:55 2016 13 // Update Count : 18 14 14 // 15 15 … … 20 20 21 21 int main( void ) { 22 ofstream *sout = ofstream_stdout();23 ifstream *sin = ifstream_stdin();24 22 vector_int vec = vector_int_allocate(); 25 23
Note:
See TracChangeset
for help on using the changeset viewer.