Changeset 0ddb713 for src/examples/iostream.c
- Timestamp:
- Dec 2, 2015, 11:58:59 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:
- 9cb8e88d
- Parents:
- 9ed3237 (diff), f2b2029 (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 edited
-
src/examples/iostream.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/examples/iostream.c
r9ed3237 r0ddb713 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:18:13201513 // Update Count : 212 // Last Modified On : Fri Nov 20 13:19:19 2015 13 // Update Count : 9 14 14 // 15 15 … … 17 17 extern "C" { 18 18 #include <stdio.h> 19 //#include <string.h> 20 //#include <ctype.h> 21 typedef long unsigned int size_t; 22 size_t strlen(const char *s); 19 #include <string.h> // strlen 23 20 } 24 21 … … 26 23 ostype * ?<<?( ostype *os, char c ) { 27 24 return write( os, &c, 1 ); 28 } 25 } // ?<<? 29 26 30 27 forall( dtype ostype | ostream( ostype ) ) 31 28 ostype * ?<<?( ostype *os, int i ) { 32 char buffer[ 20];// larger than the largest integer29 char buffer[32]; // larger than the largest integer 33 30 sprintf( buffer, "%d", i ); 34 31 return write( os, buffer, strlen( buffer ) ); 35 } 32 } // ?<<? 36 33 37 34 forall( dtype ostype | ostream( ostype ) ) 38 35 ostype * ?<<?( ostype *os, double d ) { 39 char buffer[32]; // larger than the largest double36 char buffer[32]; // larger than the largest double 40 37 sprintf( buffer, "%g", d ); 41 38 return write( os, buffer, strlen( buffer ) ); 42 } 39 } // ?<<? 43 40 44 41 forall( dtype ostype | ostream( ostype ) ) 45 42 ostype * ?<<?( ostype *os, const char *cp ) { 46 43 return write( os, cp, strlen( cp ) ); 47 } 44 } // ?<<? 45 46 forall( dtype ostype | ostream( ostype ) ) 47 ostype * ?<<?( ostype *os, const void *p ) { 48 char buffer[32]; // larger than the largest pointer 49 sprintf( buffer, "%p", p ); 50 return write( os, buffer, strlen( buffer ) ); 51 } // ?<<? 52 53 forall( type elt_type | writeable( elt_type ), 54 type iterator_type | iterator( iterator_type, elt_type ), 55 dtype os_type | ostream( os_type ) ) 56 void write( iterator_type begin, iterator_type end, os_type *os ) { 57 void print( elt_type i ) { 58 os << i << ' '; 59 } 60 for_each( begin, end, print ); 61 } // ?<<? 62 63 forall( type elt_type | writeable( elt_type ), 64 type iterator_type | iterator( iterator_type, elt_type ), 65 dtype os_type | ostream( os_type ) ) 66 void write_reverse( iterator_type begin, iterator_type end, os_type *os ) { 67 void print( elt_type i ) { 68 os << i << ' '; 69 } 70 for_each_reverse( begin, end, print ); 71 } // ?<<? 72 48 73 49 74 forall( dtype istype | istream( istype ) ) 50 75 istype * ?>>?( istype *is, char *cp ) { 51 76 return read( is, cp, 1 ); 52 } 77 } // ?>>? 53 78 54 79 forall( dtype istype | istream( istype ) ) … … 72 97 unread( is, cur ); 73 98 return is; 74 } 99 } // ?>>? 75 100 76 101 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.