source: CIVL/examples/languageFeatures/bundleUnpackApply.cvl

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/* Testing for bundle pack and unpack which invloves a flexible way of
2 reading and writing arrays. This example may still not cover all possible
3 cases. Anyone can add more send and receive pairs for different cases.
4 */
5#include <civlc.cvh>
6#include <bundle.cvh>
7#include <stdlib.h>
8
9$input int N;
10$assume(N > 4);
11$input int inputs1[3][N];
12$input int inputs2[N][3];
13$input int inputs3[2 * N];
14
15void main(){
16 int * p;
17 int * p2;
18 double ** pp;
19
20 p = (int *)malloc(sizeof(int) * 3 * N);
21 p2 = (int *)malloc(sizeof(int) * 2 * N);
22 pp = (double **)malloc(sizeof(double *) * 2);
23 for (int i = 0; i < 2; i++) {
24 pp[i] = (double *)malloc(sizeof(double) * 10);
25 for (int j = 0; j < 10; j++) pp[i][j] = i + 1;
26 }
27
28 $bundle bun;
29
30 bun = $bundle_pack(pp[0], sizeof(double) * 10);
31
32 $bundle_unpack_apply(bun, pp[1], _MAXLOC, 5, pp[0]);
33 for (int j = 0; j < 10; j++) $assert(pp[0][j] == 2);
34
35 $bundle_unpack_apply(bun, pp[1], _SUM, 10, pp[0]);
36 for (int j = 0; j < 10; j++) $assert(pp[0][j] == 3);
37
38
39 free(p);
40 free(p2);
41 free(pp[0]);
42 free(pp[1]);
43 free(pp);
44}
Note: See TracBrowser for help on using the repository browser.