| 1 | #include "header.h" |
| 2 | #include <stdlib.h> |
| 3 | #include <stdio.h> |
| 4 | |
| 5 | |
| 6 | void* new_atype(int n) { |
| 7 | struct Atype *x = malloc(sizeof(struct Atype)); |
| 8 | x->val = n; |
| 9 | return x; |
| 10 | } |
| 11 | |
| 12 | // pointer to first element of array |
| 13 | void handle_array(void *p, int n) { |
| 14 | struct Atype *ptr = (struct Atype *)p; |
| 15 | for (int i=0; i<n; i++) { |
| 16 | printf("%d - %d\n", i, ptr[i].val); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | // pointer to array |
| 21 | void handle_array2(void *p, int n) { |
| 22 | struct Atype (*ptr)[]; |
| 23 | ptr = p; |
| 24 | for (int i=0; i<n; i++) { |
| 25 | printf("%d - %d\n", i, (*ptr+i)->val); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | void destroy_atype(void *p) { |
| 30 | free(p); |
| 31 | } |
| 32 | |
| 33 | |