1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | #include<mem.cvh>
|
|---|
| 2 | #include<stdlib.h>
|
|---|
| 3 |
|
|---|
| 4 | struct T {
|
|---|
| 5 | int (*x)[100];
|
|---|
| 6 | } ** a;
|
|---|
| 7 |
|
|---|
| 8 | int main() {
|
|---|
| 9 | a = (struct T **)malloc(sizeof(struct T*));
|
|---|
| 10 | *a = (struct T*)malloc(sizeof(struct T));
|
|---|
| 11 | (*a)->x = (int (*)[100])malloc(sizeof(int[100]) * 10);
|
|---|
| 12 |
|
|---|
| 13 | $assert($mem_contains((*a)->x, &(*a)->x[0][0 .. 10])); // (*a)->x refers to the array (*a)->x[0], type of int[100]
|
|---|
| 14 | $assert(!$mem_contains((*a)->x, &(*a)->x[1][0 .. 10])); // (*a)->x does NOT points to array (*a)->x[1]
|
|---|
| 15 | $assert($mem_contains(*a, &(*a)->x)); // (*a) refers the whole struct, &(*a)->x refers to the only field
|
|---|
| 16 | $assert(!$mem_contains(*a, (*a)->x)); // (*a) refers the whole struct, (*a)->x refers to array pointed by the field
|
|---|
| 17 |
|
|---|
| 18 | free((*a)->x);
|
|---|
| 19 | free(*a);
|
|---|
| 20 | free(a);
|
|---|
| 21 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.