source: CIVL/examples/library/civlc/translate_ptr.cvl@ d87ec9c

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since d87ec9c was 5a3c0cd, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

added error checking for $free; added system functions $copy, $seq_init, $translate_ptr, etc.

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

  • Property mode set to 100644
File size: 771 bytes
Line 
1/*
2* This example demonstrates the usage of the civl system function:
3* void * $translate_ptr(void *ptr, void *obj);
4* Command line execution:
5* civl verify translate_ptr.cvl
6*/
7
8#include<civlc.h>
9
10typedef struct node{
11 int x;
12 int y;
13} node;
14
15typedef struct point{
16 double a;
17 double b;
18}point;
19
20void main(){
21 int *q;
22 double *p;
23 node *list;
24 point set[5];
25 point t;
26 double a[3][3][3];
27 int b[3][3];
28 double (*p1)[] = &a[1][2]; // p has type pointer-to-array-of-double
29
30 q = (int*)$translate_ptr(p1, &b);
31 $assert(q == &b[1][2]);
32 list = (node*)$malloc($here, sizeof(node)*5);
33 q = & (list+2)->y;
34 p = (double*)$translate_ptr(q, &t);
35 $assert(p == &t.b);
36 p = & t.a;
37 q = (int*)$translate_ptr(p, list);
38 $assert(q == &list->x);
39 $free(list);
40}
Note: See TracBrowser for help on using the repository browser.