source: CIVL/examples/modelbuilder/boolcast.cvl

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: 1.0 KB
Line 
1#include <assert.h>
2
3int f1(int a) {
4 return a + 1;
5}
6
7int f2(_Bool b) {
8 return b + 1;
9}
10
11int f3(int p1, int p2, ...) {
12 return p1 + p2;
13}
14
15int main() {
16 // case1: assign boolean to a integer and use the var
17 // in an integer context.
18 int x1 = 0;
19 int z1 = x1 + 1 == 4;
20 assert(z1 + 1 == 1);
21
22 // case2: using a boolean expression in an integer context.
23 int x2 = 0;
24 assert((x2 + 1 == 4) + 1 == 1);
25
26 // case3: assign integer to a boolean and use the var
27 // in a boolean context.
28 int x3 = 0;
29 _Bool z3 = x3 + 1;
30 if (!z3) {
31 assert(0);
32 }
33
34 // case4: using integer in a boolean context
35 int x4 = 0;
36 if (!(x4+1)) {
37 assert(0);
38 }
39
40 // case5: pass a boolean to a integer parameter in a function
41 int x5 = f1(x1 + 1 == 4);
42
43 // case6: pass an integer to a boolean parameter in a function
44 int x6 = 0;
45 int z6 = f2(x6);
46
47 // case7: pass boolean values to integer parameters in a function
48 // who has a variable number of arguments.
49
50 int x7 = 0;
51 _Bool x8 = 0;
52 int z7 = f3(x7 + 1 == 4, x8);
53
54 return 0;
55}
Note: See TracBrowser for help on using the repository browser.