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