How to represent a pointer to a C array in Rust?

后端 未结 1 1869
北荒
北荒 2020-12-11 04:25

I need an extern "C" FFI function in Rust and want to accept an array of fixed size. The C code passes something like:



        
相关标签:
1条回答
  • 2020-12-11 05:23

    You need to use Rust's syntax for fixed size arrays:

    pub unsafe extern "C" fn call_rust_funct(_p: *mut [u8; 3]) -> *mut [i32; 4] {
        Box::into_raw(Box::new([99i32; 4]))
    }
    

    You can also always use *mut std::os::raw::c_void and transmute it to the correct type.

    0 讨论(0)
提交回复
热议问题