v2 / vlib / v / tests / project_with_c_code_2 / modc / impl.c
32 lines · 26 sloc · 554 bytes · 5c93f942be81a0cbb4fcd76b241d754caccbfb8e
Raw
1#include "header.h"
2#include <stdlib.h>
3#include <stdio.h>
4
5
6void* 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
13void 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
21void 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
29void destroy_atype(void *p) {
30 free(p);
31}
32
33