source: CIVL/examples/languageFeatures/pointerSubtraction.cvl@ 63d9cfc5

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

add one more assertion

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

  • Property mode set to 100644
File size: 552 bytes
RevLine 
[b4f940a]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);
[3c4c104]24 $assert(&x[3] - x == 3);
[b4f940a]25 for(int i=0; i<3; i++)
26 $free(x[i]);
27
28 $free(x);
29 return 0;
30}
31
32
Note: See TracBrowser for help on using the repository browser.