source:
CIVL/examples/languageFeatures/int2char.cvl
| Last change on this file was ea777aa, checked in by , 3 years ago | |
|---|---|
|
|
| File size: 504 bytes | |
| Rev | Line | |
|---|---|---|
| [9803bc1] | 1 | #include <civlc.cvh> |
| [c6291e9] | 2 | #include <stdio.h> |
| 3 | ||
| 4 | $input int num; | |
| [3ff27cf] | 5 | $assume(num > 0 && num < 255); |
| [d66b03b] | 6 | |
| 7 | $scope root = $here; | |
| 8 | ||
| [c6291e9] | 9 | void main(){ |
| 10 | char c[3]; | |
| 11 | char * pc; | |
| 12 | int b = 98; // 'b' | |
| 13 | ||
| [d66b03b] | 14 | pc = (char*)$malloc(root, sizeof(char) * 3); |
| [c6291e9] | 15 | c[0] = num; |
| 16 | c[1] = 'a'; | |
| 17 | c[2] = b - 1; | |
| 18 | ||
| 19 | pc[0] = num; | |
| 20 | pc[1] = b - 1; | |
| 21 | pc[2] = 97; | |
| 22 | //test symbolic int to char | |
| [d980649] | 23 | $assert(c[0] == pc[0]); |
| [c6291e9] | 24 | //test if (char)(b-1) == 'a' |
| [d980649] | 25 | $assert(c[1] == pc[1]); |
| [c6291e9] | 26 | //test if (char)(98 - 1) == (char)97 |
| [d980649] | 27 | $assert(c[2] == pc[2]); |
| [c6291e9] | 28 | $free(pc); |
| 29 | } |
Note:
See TracBrowser
for help on using the repository browser.
