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:
799 bytes
|
| Line | |
|---|
| 1 | /* Commandline execution:
|
|---|
| 2 | * civl verify pointers.cvl
|
|---|
| 3 | * */
|
|---|
| 4 | #include<civlc.cvh>
|
|---|
| 5 |
|
|---|
| 6 | typedef struct Node {
|
|---|
| 7 | int id;
|
|---|
| 8 | struct Node* next;
|
|---|
| 9 | } Node;
|
|---|
| 10 |
|
|---|
| 11 | void passByRef(int * array) {
|
|---|
| 12 | *array = 42;
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | void main() {
|
|---|
| 16 | int a;
|
|---|
| 17 | int* b;
|
|---|
| 18 | int c[2];
|
|---|
| 19 | int* d;
|
|---|
| 20 | int** g;
|
|---|
| 21 | int* f;
|
|---|
| 22 | int *k[5];
|
|---|
| 23 | $scope myscope = $here;
|
|---|
| 24 | Node head, tail;
|
|---|
| 25 | Node *hp, *tp;
|
|---|
| 26 |
|
|---|
| 27 | tail.id = 1;
|
|---|
| 28 | tail.next = NULL;
|
|---|
| 29 | tp = &tail;
|
|---|
| 30 | head.id = 0;
|
|---|
| 31 | head.next = tp;
|
|---|
| 32 | for(int i = 0; i < 3; i++){
|
|---|
| 33 | k[i] = (int *) $malloc(myscope, sizeof(int));
|
|---|
| 34 | *k[i] = i;
|
|---|
| 35 | }
|
|---|
| 36 | k[3] = &a;
|
|---|
| 37 | k[4] = &c[0];
|
|---|
| 38 | f = &a;
|
|---|
| 39 | a = 1;
|
|---|
| 40 | b = &a;
|
|---|
| 41 | c[0] = 0;
|
|---|
| 42 | c[1] = 1;
|
|---|
| 43 | d = &c[1];
|
|---|
| 44 | g = &d;
|
|---|
| 45 | $assert(*b == 1);
|
|---|
| 46 | $assert(*d == 1);
|
|---|
| 47 | $assert(**g == 1);
|
|---|
| 48 | $assert(g == &d);
|
|---|
| 49 | passByRef(f);
|
|---|
| 50 | $assert(*f == 42);
|
|---|
| 51 | $free(k[0]);
|
|---|
| 52 | $free(k[1]);
|
|---|
| 53 | $free(k[2]);
|
|---|
| 54 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.