Pointers 从Rust FFI检索指向浮点的指针

Pointers 从Rust FFI检索指向浮点的指针,pointers,ffi,rust,Pointers,Ffi,Rust,Ubuntu 13.04,Rust 0.6。我正试图用生锈的FFI来操作openblas。以下代码无法按预期工作 use core::io::println; use core::libc::{c_int, c_float}; use core::vec::raw::to_ptr; extern mod openblas { /* Single precision dot product. sdot takes 5 args: number of elements,

Ubuntu 13.04,Rust 0.6。我正试图用生锈的FFI来操作openblas。以下代码无法按预期工作

use core::io::println;
use core::libc::{c_int, c_float};
use core::vec::raw::to_ptr;

extern mod openblas {
    /*  Single precision dot product.
        sdot takes 5 args: number of elements,
                           pointer to a,
                           storage spacing for elements of a,
                           pointer to b,
                           storage spacing for elements of b
        returns a^T . b
    */
    fn cblas_sdot(N: c_int, x: *c_float, incx: c_int,
                  y: *c_float, incy: c_int) -> *c_float;
}

pub fn sdot(a: &[c_float], b: &[c_float]) -> *c_float {
    unsafe {
        openblas::cblas_sdot(3 as c_int, to_ptr(a), 1 as c_int,
                             to_ptr(b), 1 as c_int)
    }
}

fn main() {
    let a = [1. as c_float, 2. as c_float, 4. as c_float];
    let b = [1. as c_float, 2. as c_float, 5. as c_float];
    let x = sdot(a, b);
    println(fmt!("%?", x));

}
编辑:我希望它打印25,作为一个借来的指针。我得到了140125321300160,这可能是浮点的地址。

cblas_sdot函数不应该返回指针

发件人:

cblas_sdot

单精度计算两个向量的点积

浮点数cblas_sdotconst int N、const float*X、const int incX、const float*Y、const int incY

cblas_sdot函数不应返回指针

发件人:

cblas_sdot

单精度计算两个向量的点积

浮点数cblas_sdotconst int N、const float*X、const int incX、const float*Y、const int incY


您可以发布您期望发生的事情以及发生的事情吗?完成,谢谢您的提醒。请尝试printlnfmt!%*十,。我不确定,如果没有openblas,我无法检查-我被困在Windows上。你能发布你预期会发生什么,发生了什么吗?完成,谢谢你的提醒。尝试printlnfmt!%*十,。我不确定,如果没有openblas,我无法检查——我被困在Windows上。