...And may crash the program. But passing by reference does work properly.
While passing struct by value:
- With 1 field -> Ok
- With 2 field -> Second field is zero
- With 3 field -> Crash
Example C library:
typedef struct {int a, b, c} i3;
void checkByRef(i3 *s) { printf("%d, %d, %d\n", s->a, s->b, s->c); }
void checkByVal(i3 s) { printf("%d, %d, %d\n", s.a, s.b, s.c); }
Adept:
record i3(a, b, c int)
foreign checkByRef(s *i3) void
foreign checkByVal(s i3) void
func main {
v i3 = i3(1, 2, 3)
checkByRef(&v) // Ok
checkByVal(v) // Crash
}
Test case
Related issue to discussion #337. Luckily, that problem can be resolved because the 4 ubyte struct is packed into a single int.