C档案:
typedef struct point {
int x;
int y;
} point;
typedef struct points {
int count;
point *array_of_points;
} points;
锈文件:
#[derive(Debug)]
#[repr(C)]
pub struct point {
x: c_int,
y: c_int,
}
#[derive(Debug)]
#[repr(C)]
pub struct points {
count: c_int,
array_of_points: [point],
}
#[no_mangle]
pub fn do_something(all_points: &points) {
for i in 0..all_points.count {
let crr_point = &all_points.array_of_points[i as usize];
println!("{:?}", crr_point);
}
}
在我的C文件中,我分配了很多结构点并将它们添加到array_of_points
,然后我调用do_something
函数。
如何在Rust中的array_of_points
获得每个单点?
我是否正确定义了Rust中的array_of_points
数组?
当我运行它时,会出现这种奇怪的结果:
point { x: 0, y: -952095696 }
point { x: 32674, y: 101 }
等等。