#include "stdlib.hfa" #include "array.hfa" forall( ztype(Nclients), ztype(Ncosts) ) struct request { unsigned int requestor_id; array( unsigned int, Nclients ) impacted_client_ids; array( float, Ncosts ) cost_contribs; float total_cost; }; // TODO: understand (fix?) why these are needed (autogen seems to be failing ... is typeof as struct member nayok?) forall( ztype(Nclients), ztype(Ncosts) ) void ?{}( request(Nclients, Ncosts) & this ) {} forall( ztype(Nclients), ztype(Ncosts) ) void ^?{}( request(Nclients, Ncosts) & this ) {} forall( ztype(Nclients), ztype(Ncosts) ) void summarize( request(Nclients, Ncosts) & r ) { r.total_cost = 0; for( i; z(Ncosts) ) r.total_cost += r.cost_contribs[i]; // say the cost is per-client, to make output vary r.total_cost *= z(Nclients); } int main( int argc, char ** argv ) { const int ncl = atoi(argv[1]); const int nco = 2; request( Z(ncl), Z(nco) ) r; r.cost_contribs[0] = 100; r.cost_contribs[1] = 0.1; summarize(r); printf("Total cost: %.1f\n", r.total_cost); /* ./a.out 5 Total cost: 500.5 ./a.out 6 Total cost: 600.6 */ }