source:
CIVL/examples/languageFeatures/pointers.cvl@
1258be5
| Last change on this file since 1258be5 was 36b5ada, checked in by , 12 years ago | |
|---|---|
|
|
| File size: 400 bytes | |
| Rev | Line | |
|---|---|---|
| [36b5ada] | 1 | /* Commandline execution: |
| 2 | * civl verify pointers.cvl | |
| 3 | * */ | |
| [6543229] | 4 | #include<civlc.h> |
| 5 | ||
| [40a899c] | 6 | void passByRef(int * array) { |
| 7 | *array = 42; | |
| 8 | } | |
| 9 | ||
| [6543229] | 10 | void main() { |
| 11 | int a; | |
| 12 | int* b; | |
| 13 | int c[2]; | |
| 14 | int* d; | |
| [b6565a0] | 15 | int** g; |
| [40a899c] | 16 | int* f; |
| [b6565a0] | 17 | |
| [40a899c] | 18 | f = &a; |
| [6543229] | 19 | a = 1; |
| 20 | b = &a; | |
| 21 | c[0] = 0; | |
| 22 | c[1] = 1; | |
| 23 | d = &c[1]; | |
| [b6565a0] | 24 | g = &d; |
| [6543229] | 25 | $assert *b == 1; |
| 26 | $assert *d == 1; | |
| [b6565a0] | 27 | $assert **g == 1; |
| [40a899c] | 28 | $assert g == &d; |
| 29 | passByRef(f); | |
| 30 | $assert *f == 42; | |
| [6543229] | 31 | } |
Note:
See TracBrowser
for help on using the repository browser.
