Closed
Description
This is somewhat complicated and requires an intermediate crate. There is no error (as far as this test can tell) if the intermediate crate is removed. Take these 3 files:
bug.c
#include <stdio.h>
typedef struct
{
float a, b, c, d;
} S;
void test(S a)
{
printf("%f %f %f %f\n", a.a, a.b, a.c, a.d);
}
bug.rs
#![crate_id="bug"]
#![crate_type="lib"]
pub struct S
{
pub a: f32,
pub b: f32,
pub c: f32,
pub d: f32,
}
#[link(name = "bug")]
extern "C"
{
pub fn test(b: S);
}
test.rs
extern crate bug;
use bug::{test, S};
fn main()
{
unsafe
{
let s1 = S{a: 1.0, b: 2.0, c: 3.0, d: 4.0};
test(s1);
}
}
Compile it all together and run test.exe
:
gcc -shared bug.c -olibbug.dll
rustc bug.rs
rustc test.rs -L.
test
The output I get is:
0.000000 0.000000 1.000000 2.000000
Expected output:
1.000000 2.000000 3.000000 4.000000
GCC version:
gcc (rev5, Built by MinGW-W64 project) 4.8.1