source: CIVL/examples/languageFeatures/pointerSubtraction.cvl@ d8d938c

1.23 2.0 main test-branch
Last change on this file since d8d938c was b4f940a, checked in by Ziqing Luo <ziqing@…>, 12 years ago

add examples for pointer subtraction

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

  • Property mode set to 100644
File size: 525 bytes
Line 
1#include <stdlib.h>
2#include <civlc.h>
3
4int main(){
5 double (*p)[2];
6 double * q;
7 double a[3][2];
8 double b[3][2];
9 double **x;
10
11 p = a; //p == &a[0]
12 q = &b[0][0];
13 p += 1;
14 q += 6;
15 x = (double **)$malloc($root, sizeof(double *) * 3);
16
17 for(int i=0; i<3; i++)
18 x[i] = (double *)$malloc($root, sizeof(double) * 2);
19
20 $assert((p - a) == 1);
21 $assert((q - &b[0][0]) == 6);
22 $assert(&x[0] - &x[2] == -2);
23 $assert(&x[0][1] - x[0] == 1);
24 for(int i=0; i<3; i++)
25 $free(x[i]);
26
27 $free(x);
28 return 0;
29}
30
31
Note: See TracBrowser for help on using the repository browser.