source: CIVL/examples/library/civlc/translate_ptr.cvl@ 178c915

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

added system function translate_ptr() and a test method accordingly.

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

  • Property mode set to 100644
File size: 603 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
27 list = (node*)$malloc($here, sizeof(node)*5);
28 q = & (list+2)->y;
29 p = (double*)$translate_ptr(q, &t);
30 $assert(p == &t.b);
31 p = & t.a;
32 q = (int*)$translate_ptr(p, list);
33 $assert(q == &list->x);
34 $free(list);
35}
Note: See TracBrowser for help on using the repository browser.