Closed
Description
Note that I only tested this with a quad of f32's, I imagine it fails for several other numbers/sizes of floats too. Tested with rust at dc4560d.
You need two files, test.c
and test.rs
:
test.c
:
#include <stdio.h>
typedef struct
{
float a, b, c, d;
} A;
A get()
{
A a = {1, 2, 3, 4};
return a;
}
void test(A a)
{
printf("%f %f %f %f\n", a.a, a.b, a.c, a.d);
}
test.rs
:
struct A
{
a : f32,
b : f32,
c : f32,
d : f32,
}
#[link_args = "-ltest"]
extern "C"
{
fn get() -> A;
fn test(a : A);
}
fn main()
{
unsafe
{
let a = get();
println(fmt!("%?", a));
let b = A{a: 0.1, b: 0.2, c: 0.3, d: 0.4};
test(b);
}
}
Compile using this code:
gcc -c test.c
ar -cvq libtest.a test.o
rustc test.rs -L.
The output when running test
on my system is:
./test
{a: 0, b: 1, c: 0, d: 0}
0.100000 0.200000 0.200000 0.000000
The expected output is:
./test
{a: 1, b: 2, c: 3, d: 4}
0.100000 0.200000 0.300000 0.400000