1 | #include <fstream.hfa> |
---|
2 | #include <stdlib.hfa> |
---|
3 | #include <array.hfa> |
---|
4 | #include <locale.h> // setlocale |
---|
5 | |
---|
6 | |
---|
7 | |
---|
8 | |
---|
9 | |
---|
10 | forall( T, @[NprovTerty]@, @[Nmunicipalities]@ ) |
---|
11 | struct CanPop { |
---|
12 | array( T, @NprovTerty@ ) provTerty; $\C{// nested VLA}$ |
---|
13 | array( T, @Nmunicipalities@ ) municipalities; $\C{// nested VLA}$ |
---|
14 | int total_pt, total_mun; |
---|
15 | }; |
---|
16 | |
---|
17 | |
---|
18 | // TODO: understand (fix?) why these are needed (autogen seems to be failing ... is typeof as struct member nayok?) |
---|
19 | |
---|
20 | forall( T, [NprovTerty], [Nmunicipalities] ) |
---|
21 | void ?{}( T &, CanPop( T, NprovTerty, Nmunicipalities ) & this ) {} |
---|
22 | |
---|
23 | forall( T &, [NprovTerty], [Nmunicipalities] ) |
---|
24 | void ^?{}( CanPop( T, NprovTerty, Nmunicipalities ) & this ) {} |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | forall( T, [NprovTerty], [Nmunicipalities] ) |
---|
41 | void check( CanPop( T, NprovTerty, Nmunicipalities ) & pop ) with( pop ) { |
---|
42 | total_pt = total_mun = 0; |
---|
43 | for ( i; NprovTerty ) total_pt += provTerty[i]; |
---|
44 | for ( i; Nmunicipalities ) total_mun += municipalities[i]; |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | int main( int argc, char * argv[] ) { |
---|
61 | const int npt = ato( argv[1] ), nmun = ato( argv[2] ); |
---|
62 | @CanPop( int, npt, nmun ) pop;@ |
---|
63 | // read in population numbers |
---|
64 | @check( pop );@ |
---|
65 | sout | setlocale( LC_NUMERIC, getenv( "LANG" ) ); |
---|
66 | sout | "Total province/territory:" | pop.total_pt; |
---|
67 | sout | "Total municipalities:" | pop.total_mun; |
---|
68 | } |
---|
69 | /* |
---|
70 | $\$$ ./a.out 13 3573 |
---|
71 | Total province/territory: 36,991,981 |
---|
72 | Total municipalities: 36,991,981 |
---|
73 | $\$$ ./a.out 13 3654 |
---|
74 | Total province/territory: 36,991,981 |
---|
75 | Total municipalities: 36,991,981 |
---|
76 | */ |
---|
77 | |
---|
78 | // Local Variables: // |
---|
79 | // compile-command: "sed -f sedcmd hello-accordion.cfa > ../build/tmp.cfa; cfa ../build/tmp.cfa -Wall -Wextra" // |
---|
80 | // End: // |
---|