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:
795 bytes
|
| Rev | Line | |
|---|
| [e1083b3] | 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 |
|
|---|
| [4208097] | 8 | #include<civlc.cvh>
|
|---|
| 9 | #include<pointer.cvh>
|
|---|
| [e1083b3] | 10 |
|
|---|
| 11 | typedef struct node{
|
|---|
| 12 | int x;
|
|---|
| 13 | int y;
|
|---|
| 14 | } node;
|
|---|
| 15 |
|
|---|
| 16 | typedef struct point{
|
|---|
| 17 | double a;
|
|---|
| 18 | double b;
|
|---|
| 19 | }point;
|
|---|
| 20 |
|
|---|
| 21 | void main(){
|
|---|
| 22 | int *q;
|
|---|
| 23 | double *p;
|
|---|
| 24 | node *list;
|
|---|
| 25 | point set[5];
|
|---|
| 26 | point t;
|
|---|
| [5a3c0cd] | 27 | double a[3][3][3];
|
|---|
| 28 | int b[3][3];
|
|---|
| 29 | double (*p1)[] = &a[1][2]; // p has type pointer-to-array-of-double
|
|---|
| [e1083b3] | 30 |
|
|---|
| [5a3c0cd] | 31 | q = (int*)$translate_ptr(p1, &b);
|
|---|
| [d980649] | 32 | $assert(q == &b[1][2]);
|
|---|
| [e1083b3] | 33 | list = (node*)$malloc($here, sizeof(node)*5);
|
|---|
| 34 | q = & (list+2)->y;
|
|---|
| 35 | p = (double*)$translate_ptr(q, &t);
|
|---|
| [d980649] | 36 | $assert(p == &t.b);
|
|---|
| [e1083b3] | 37 | p = & t.a;
|
|---|
| 38 | q = (int*)$translate_ptr(p, list);
|
|---|
| [d980649] | 39 | $assert(q == &list->x);
|
|---|
| [e1083b3] | 40 | $free(list);
|
|---|
| 41 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.