source: CIVL/examples/languageFeatures/memcpy.cvl@ b50d2e7

1.23 2.0 main test-branch
Last change on this file since b50d2e7 was 36b5ada, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

Cleaned up examples.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@424 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.0 KB
Line 
1/* Commandline execution:
2 * civl verify memcpy.cvl
3 * */
4#include<civlc.h>
5
6typedef struct foo {
7 int f0;
8 double f1;
9 int f2;
10 long double f3;
11} foo;
12
13typedef struct bar{
14 foo f0;
15 int f1[8];
16} bar;
17
18void main() {
19 int a[10], b[5];
20 foo foo1, foo2;
21
22 // Basic array component.
23 for (int i = 0; i < 10; i++) {
24 a[i] = i;
25 }
26 memcpy(b, a, 5*sizeof(int));
27 for (int i = 0; i < 5; i++) {
28 $assert b[i] == i;
29 }
30
31 // Basic struct copy.
32 foo1.f0 = 3;
33 foo1.f1 = 3.14;
34 foo1.f2 = 0;
35 foo1.f3 = 2.71828;
36 memcpy(&foo2, &foo1, sizeof(foo));
37 $assert foo2.f0 == 3;
38 $assert foo2.f1 == 3.14;
39 $assert foo2.f2 == 0;
40 $assert foo2.f3 == 2.71828;
41
42 // Modify struct fields.
43 bar bar1;
44 memcpy(&(bar1.f0), &foo2, sizeof(foo));
45 memcpy(&(bar1.f1[3]), b, 5*sizeof(int));
46 $assert bar1.f0.f0 == 3;
47 $assert bar1.f1[3] == 0;
48 memcpy(bar1.f1, a, 4*sizeof(int));
49 $assert bar1.f1[0] == 0;
50 $assert bar1.f1[3] == 3;
51 $assert bar1.f1[5] == 2;
52 $assert bar1.f0.f1 == 3.14;
53 bar1.f0.f1 = 9.99;
54 $assert foo2.f1 == 3.14;
55}
Note: See TracBrowser for help on using the repository browser.