|
| 1 | +#include <inttypes.h> |
| 2 | + |
| 3 | +#include <stdlib.h> |
| 4 | +#include <stdbool.h> |
| 5 | +#include <stdio.h> |
| 6 | +#include <string.h> |
| 7 | +#include <lfortran_intrinsics.h> |
| 8 | + |
| 9 | +struct dimension_descriptor |
| 10 | +{ |
| 11 | + int32_t lower_bound, length; |
| 12 | +}; |
| 13 | +struct __attribute__((packed)) inner_struct { |
| 14 | + int32_t inner_field; |
| 15 | +}; |
| 16 | + |
| 17 | +struct __attribute__((packed)) outer_struct { |
| 18 | + struct inner_struct inner_s; |
| 19 | +}; |
| 20 | + |
| 21 | + |
| 22 | +inline void struct_deepcopy_outer_struct(struct outer_struct* src, struct outer_struct* dest); |
| 23 | +inline void struct_deepcopy_inner_struct(struct inner_struct* src, struct inner_struct* dest); |
| 24 | + |
| 25 | + |
| 26 | +// Implementations |
| 27 | +void check() |
| 28 | +{ |
| 29 | + struct inner_struct inner_struct_instance_value; |
| 30 | + struct inner_struct* inner_struct_instance = &inner_struct_instance_value; |
| 31 | + struct outer_struct outer_struct_instance_value; |
| 32 | + struct outer_struct* outer_struct_instance = &outer_struct_instance_value; |
| 33 | + struct outer_struct outer_struct_instance2_value; |
| 34 | + struct outer_struct* outer_struct_instance2 = &outer_struct_instance2_value; |
| 35 | + outer_struct_instance->inner_s.inner_field = 5; |
| 36 | + struct_deepcopy_outer_struct(outer_struct_instance, outer_struct_instance2); |
| 37 | + struct_deepcopy_inner_struct(&outer_struct_instance2->inner_s, inner_struct_instance); |
| 38 | + ASSERT(inner_struct_instance->inner_field == 5); |
| 39 | +} |
| 40 | + |
| 41 | +void _lpython_main_program() |
| 42 | +{ |
| 43 | + check(); |
| 44 | +} |
| 45 | + |
| 46 | +int main(int argc, char* argv[]) |
| 47 | +{ |
| 48 | + _lpython_set_argv(argc, argv); |
| 49 | + _lpython_main_program(); |
| 50 | + return 0; |
| 51 | +} |
| 52 | + |
| 53 | +void struct_deepcopy_inner_struct(struct inner_struct* src, struct inner_struct* dest) { |
| 54 | + dest->inner_field = src->inner_field; |
| 55 | +} |
| 56 | + |
| 57 | +void struct_deepcopy_outer_struct(struct outer_struct* src, struct outer_struct* dest) { |
| 58 | + struct_deepcopy_inner_struct(&(src->inner_s), &(dest->inner_s));; |
| 59 | +} |
| 60 | + |
| 61 | + |
0 commit comments