Changeset 930b504 for doc/papers/concurrency/examples/Format1.c
- Timestamp:
- Feb 26, 2020, 6:13:54 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 04e6f93, 5452673, dac55004
- Parents:
- aeb5d0d (diff), 7dc2e015 (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
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/concurrency/examples/Format1.c
raeb5d0d r930b504 2 2 3 3 typedef struct { 4 void * next;4 int restart, g, b; 5 5 char ch; 6 int g, b;7 6 } Fmt; 8 7 9 8 void format( Fmt * f ) { 10 if ( __builtin_expect(f->next != 0, 1) ) goto *f->next; 11 f->next = &&s1; 9 static void * states[] = {&&s0, &&s1}; 10 goto *states[f->restart]; 11 s0: f->restart = 1; 12 12 for ( ;; ) { 13 13 for ( f->g = 0; f->g < 5; f->g += 1 ) { // groups 14 14 for ( f->b = 0; f->b < 4; f->b += 1 ) { // blocks 15 15 return; 16 s1: ; 17 if ( f->ch == '\0' ) goto fini; // EOF ? 16 s1: if ( f->ch == '\0' ) goto fini; // EOF ? 18 17 while ( f->ch == '\n' ) return; // ignore 19 printf( "%c", f->ch ); // print character18 // printf( "%c", f->ch ); // print character 20 19 } 21 printf( " " ); // block separator20 // printf( " " ); // block separator 22 21 } 23 printf( "\n" ); // group separator22 // printf( "\n" ); // group separator 24 23 } 25 fini: 26 if ( f->g != 0 || f->b != 0 ) printf( "\n" );24 fini:; 25 // if ( f->g != 0 || f->b != 0 ) printf( "\n" ); 27 26 } 28 27 29 28 int main() { 30 Fmt fmt = { NULL};29 Fmt fmt = { 0 }; 31 30 format( &fmt ); // prime 32 for ( ;; ) { 33 scanf( "%c", &fmt.ch ); // direct read into communication variable 34 if ( feof( stdin ) ) break; 31 fmt.ch = 'a'; 32 for ( long int i = 0; i < 1000000000; i += 1 ) { 33 // scanf( "%c", &fmt.ch ); // direct read into communication variable 34 // if ( feof( stdin ) ) break; 35 35 format( &fmt ); 36 36 } 37 fmt.ch = '\0'; 37 fmt.ch = '\0'; // sentential (EOF) 38 38 format( &fmt ); 39 39 }
Note: See TracChangeset
for help on using the changeset viewer.