blob: df95e1cae462bc1c5cc054574f98dcf905de5580 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
typedef struct Person {
int age;
} Person;
typedef struct PersonArray {
unsigned int length;
int pad;
Person* data[];
} PersonArray;
__attribute__ ((CALL_CONV))
extern void fcn(PersonArray* people, int index);
int main() {
Person base[5] = {{25},{1},{18},{45},{60}};
unsigned char buf[8+8*5];
PersonArray* people_array = (PersonArray*)buf;
people_array->length=5;
for (int i=0; i<people_array->length; i++) people_array->data[i] = &base[i];
fcn(people_array, 1);
fcn(people_array, 1);
fcn(people_array, 1);
fcn(people_array, 1);
fcn(people_array, 1);
printf("%d\n", people_array->data[1]->age); // expected: 6
return 0;
}
|