ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change
on this file since 2210cfc was
a573c22,
checked in by Peter A. Buhr <pabuhr@…>, 5 years ago
|
example programs updated for concurrency paper
|
-
Property mode set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | #include <stdio.h> |
---|
2 | |
---|
3 | typedef struct { |
---|
4 | int restart, g, b; |
---|
5 | char ch; |
---|
6 | } Fmt; |
---|
7 | |
---|
8 | void format( Fmt * f ) { |
---|
9 | static void * states[] = {&&s0, &&s1}; |
---|
10 | goto *states[f->restart]; |
---|
11 | s0: f->restart = 1; |
---|
12 | for ( ;; ) { |
---|
13 | for ( f->g = 0; f->g < 5; f->g += 1 ) { // groups |
---|
14 | for ( f->b = 0; f->b < 4; f->b += 1 ) { // blocks |
---|
15 | return; |
---|
16 | s1: if ( f->ch == '\0' ) goto fini; // EOF ? |
---|
17 | while ( f->ch == '\n' ) return; // ignore |
---|
18 | // printf( "%c", f->ch ); // print character |
---|
19 | } |
---|
20 | // printf( " " ); // block separator |
---|
21 | } |
---|
22 | // printf( "\n" ); // group separator |
---|
23 | } |
---|
24 | fini:; |
---|
25 | // if ( f->g != 0 || f->b != 0 ) printf( "\n" ); |
---|
26 | } |
---|
27 | |
---|
28 | int main() { |
---|
29 | Fmt fmt = { 0 }; |
---|
30 | format( &fmt ); // prime |
---|
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 | format( &fmt ); |
---|
36 | } |
---|
37 | fmt.ch = '\0'; // sentential (EOF) |
---|
38 | format( &fmt ); |
---|
39 | } |
---|
40 | |
---|
41 | // Local Variables: // |
---|
42 | // tab-width: 4 // |
---|
43 | // compile-command: "gcc-8 Format1.c" // |
---|
44 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.