source: CIVL/examples/library/string/memcpy.cvl@ bb03188

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